android google map的使用
16lz
2021-01-23
使用google map 需要注册 Android 地图 API 密钥
方法如下:
1. 首先先要获取你的debug keystore位置:
打开Eclipse--->Windows--->Preferences--->Android--->Build
查看默认的debug keystore位置,我的是C:\Documents and Settings\MYNAME \.android\debug.keystore
2. 在cmd中运行:
keytool -list -keystore 第一步找到的路径/.android/debug.keystore 注意加上引号
回车后出现输入密码:直接回车就可以了
执行结果:
androiddebugkey, May 4, 2009, PrivateKeyEntry,
Certificate fingerprint (MD5): XX:XX:XX:XX:XX:XX:XX:XX.............
这里的XX:XX:XX:XX:XX:XX:XX:XX.............就是你的认证指纹
3. 打开http://code.google.com/intl/zh-CN/android/maps-api-signup.html
4. 使用得到的apiKey:
在layout中加入MapView
5.在manifest.xml 加上权限
6.建立工程
注意这里要选择的buildtarget为"GoogleAPIs" 建立google api adv
如果用到了google api 那么就需要在建立google 的 adv,跟新建普通的adv一样,
eclipse --windows---virtual devices--new---出来对话框在target选择google apis 即OK
7.activity code
方法如下:
1. 首先先要获取你的debug keystore位置:
打开Eclipse--->Windows--->Preferences--->Android--->Build
查看默认的debug keystore位置,我的是C:\Documents and Settings\MYNAME \.android\debug.keystore
2. 在cmd中运行:
keytool -list -keystore 第一步找到的路径/.android/debug.keystore 注意加上引号
回车后出现输入密码:直接回车就可以了
执行结果:
androiddebugkey, May 4, 2009, PrivateKeyEntry,
Certificate fingerprint (MD5): XX:XX:XX:XX:XX:XX:XX:XX.............
这里的XX:XX:XX:XX:XX:XX:XX:XX.............就是你的认证指纹
3. 打开http://code.google.com/intl/zh-CN/android/maps-api-signup.html
4. 使用得到的apiKey:
在layout中加入MapView
<com.google.android.maps.MapView android:id="@+id/mapview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:apiKey="XXXXXXXXXXXXXXXXXXXXXXXXXXXX" />
5.在manifest.xml 加上权限
<uses-library android:name="com.google.android.maps"></uses-library> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
6.建立工程
注意这里要选择的buildtarget为"GoogleAPIs" 建立google api adv
如果用到了google api 那么就需要在建立google 的 adv,跟新建普通的adv一样,
eclipse --windows---virtual devices--new---出来对话框在target选择google apis 即OK
7.activity code
public class TestMap extends MapActivity { /** Called when the activity is first created. */private MapView mapView = null;private MapController mapCon = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mapView = (MapView)findViewById(R.id.map); // 设置显示模式 // mapView.setTraffic(true); mapView.setSatellite(false); mapView.setStreetView(false); //设置缩放模式 mapView.setBuiltInZoomControls(true); // 设置初始地图的中心位置 113°46' 22°27' 39.95 116.37 GeoPoint geoBeijing=new GeoPoint((int)(22.27*1000000), (int)(113.46*1000000)); mapCon=mapView.getController(); mapCon.setCenter(geoBeijing); mapCon.setZoom(15); }
更多相关文章
- Android开发:观察者模式应用实例
- Android(OPhone) 学习笔记 - 地图(2)
- Android 的 Recovery 模式分析
- Android夜间模式实现(系统自带)
- android 开发谷歌地图的步骤