demo运行前请确保安装了GoogleAPI的android插件,(请采用GoogleAPI模式)
package com.royal.googleMap;
import java.util.List;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.os.Bundle;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
public class GoogleMapDemoActivity extends MapActivity {
private MapView mapView;
private GeoPoint geoPoint;
private MapController mapController;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.map_view);
// mapView = new MapView(this,"05RuQFhSv2zb5X5u91S0hcsIdcVwFNfwrE__18w");
// 设置为交通模式
// mapView.setTraffic(true);
// 设置为卫星模式
// mapView.setSatellite(true);
// 设置为街景模式
mapView.setStreetView(true);
// 取得MapController对象(控制MapView)
mapController = mapView.getController();
mapView.setEnabled(true);
mapView.setClickable(true);
// 设置地图支持缩放
mapView.setBuiltInZoomControls(true);
// 设置起点
geoPoint = new GeoPoint((int) (22.744680959764427 * 1000000),
(int) (113.59523713588715 * 1000000));
// 定位
mapController.animateTo(geoPoint);
// 设置倍数(1-21)
mapController.setZoom(12);
// 添加Overlay,用于显示标注信息
MyLocationOverlay myLocationOverlay = new MyLocationOverlay();
List<Overlay> list = mapView.getOverlays();
list.add(myLocationOverlay);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
/**
* 绘图类
* @author Royal
*
*/
class MyLocationOverlay extends Overlay {
@Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
long when) {
// TODO Auto-generated method stub
super.draw(canvas, mapView, shadow);
Paint paint = new Paint();
Point myScreenCoords = new Point();
// 将经纬度转换成实际屏幕坐标
mapView.getProjection().toPixels(geoPoint, myScreenCoords);
paint.setStrokeWidth(1);
paint.setARGB(255, 255, 0, 0);
paint.setStyle(Paint.Style.STROKE);
Bitmap bmp = BitmapFactory.decodeResource(getResources(),
R.drawable.home);
canvas.drawBitmap(bmp, myScreenCoords.x, myScreenCoords.y, paint);
canvas.drawText("Here am I", myScreenCoords.x, myScreenCoords.y, paint);
return true;
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.royal.googleMap"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<!-- 声明适用Google Map API -->
<uses-library android:name="com.google.android.maps"/>
<activity
android:label="@string/app_name"
android:name=".GoogleMapDemoActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
- 大小: 14 KB
分享到:
相关推荐
GoogleMapDemo是一个简单的基于Google Maps Android API v2的demo并实现了通过...【注意:】运行此demo项目前,需要在AndroidManifest.xml设置你自己的googleMap key和相应的keystore,否则运行后地图显示一片空白。
一个简单的Android实现GoogleMapApi v2展示Demo,注意:需下载安装Google Play ,需自己在google官方申请地图API Key, 需依赖google-play-services_lib作为类库(google-play-services_lib已有)
今天发了半天时间才把google map 这个demo搞定,中间走了不少弯路,特意记录下,备份。
android安卓绝对可以获取GPS经纬度的google map demo。使用谷歌api,不需要网络,可以直接获取经纬度,获取经纬度写到一个类中,直接调用start,关闭使用stop。 注意要在室外使用! 打开应用,马上开始获取地址,多次...
Android google map简单加载地图,能直接运行显示出地图。
新手做的例子,版本是2.2的,需要将res\layout\main.xml中更换成为自己的apiKey,还需要专门下载Google Map的开发包,简单标记所在位置的小Demo,有不足之处请指出
Android上演示调用谷歌地图的演示DEMO,需要手机先安装谷歌服务
本人开发时做的一部分,使用Googlemap定位可用。
google map demo .rar 一个关于地图的例子
Google Map的简单使用.Android PhotoBrowse_SDCard demo
android google map api 地图导航系统,是源代码,直接可以使用的,希望分享给大家
Android应用源码开发Demo,主要用于毕业设计学习。
GoogleMapDemo 演示应用程序能够在Google Map上显示所选位置
Android应用源码开发Demo,主要用于毕业设计学习。
Android应用源码开发Demo,主要用于毕业设计学习。
基于Google Map 的简单demo,实现Googlemap的基本功能
Because using Google Play Services to show a Google Map may be overkill, or simply because Google Play Services are not available (Amazon, I'm looking at you!). How? Most of the official API is ...
android写的google map api 应用.rar android基于自定义适配器的ExpandableListView.zip Android无线点餐系统.rar Android模仿乐淘的应用程序分析源码.zip 15个Android很有用的代码片段.pdf 3G应用开发之Android.ppt...
android写的google map api 应用.rar android基于自定义适配器的ExpandableListView.zip Android无线点餐系统.rar Android模仿乐淘的应用程序分析源码.zip android源代码分析.rar android源码一个柱状图的Demo.zip ...
Android google map view Library by static map A library to make the map display process easier by entering latitude and longitude only Do not forget the star:)⭐️ GoogleMapView APK Demo How to ...