Android(安卓)Maps
16lz
2021-12-04
查了不少网址终于把android maps搞定,总结如下:
0.环境: 0.1 android-sdk-windows-1.0_r2.zip 0.2 eclipse-java-europa-winter-win32.zip v3.3.2 + SDK Plugin 1.API KEY 申请 C:/Documents and Settings/3-301-1/Local Settings/Application Data/Android>keytoo l -list -alias androiddebugkey -keystore debug.keystore -storepass android -keyp ass android androiddebugkey, 2008-12-6, PrivateKeyEntry, 认证指纹 (MD5): ×××××××××××××××××××××××××××××××××××××× ×××××××××××××××××××××××××××××××××××××× ×××××××××××××××××××××××××××××××××××××× <com.google.android.maps.MapView android:layout_width="fill_parent" android:layout_height="fill_parent" android:apiKey="××××××××××××××××××××××××××××××××××××××" /> 2.编写程序 http://www.qphone.net/ http://www.qphone.net/2008/12/21/android平台上的mapview开发-2-一个读取地图并且可以缩放设置/ 2.1设置上网权限 <uses-permission android:name="android.permission.INTERNET" /> 2.2设置界面xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <com.google.android.maps.MapView android:id="@+id/map" android:layout_width="fill_parent" android:layout_height="fill_parent" android:apiKey="××××××××××××××××××××××××××××××××××××××" android:clickable="true" /> </RelativeLayout> 2.3源代码- packagecom.chen;
- importandroid.os.Bundle;
- importandroid.view.View;
- importandroid.widget.Button;
- importcom.google.android.maps.GeoPoint;
- importcom.google.android.maps.MapActivity;
- importcom.google.android.maps.MapController;
- importcom.google.android.maps.MapView;
- publicclassBasicMapAppextendsMapActivity{
- MapViewmapView;
- MapControllermapController;
- booleanisSatellite=false;
- @Override
- publicvoidonCreate(Bundleicicle){
- super.onCreate(icicle);
- setContentView(R.layout.main);
- mapView=(MapView)findViewById(R.id.map);
- mapController=mapView.getController();
- mapController.setZoom(15);
- updateView();
- }
- privatevoidupdateView(){
- Doublelat=31.23717*1E6;
- Doublelng=121.50811*1E6;
- GeoPointpoint=newGeoPoint(lat.intValue(),lng.intValue());
- mapController.setCenter(point);
- //放大地图,缩放等级加
- ButtonbtnZoomIn=(Button)findViewById(R.id.zoomin);
- btnZoomIn.setOnClickListener(newView.OnClickListener(){
- publicvoidonClick(Viewview){
- mapController.setZoom(mapView.getZoomLevel()+1);
- }
- });
- //缩小地图,缩放等级减
- ButtonbtnZoomOut=(Button)findViewById(R.id.zoomout);
- btnZoomOut.setOnClickListener(newView.OnClickListener(){
- publicvoidonClick(Viewview){
- mapController.setZoom(mapView.getZoomLevel()-1);
- }
- });
- //缩小地图,缩放等级减
- ButtonbtnSatellite=(Button)findViewById(R.id.satellite);
- btnSatellite.setOnClickListener(newView.OnClickListener(){
- publicvoidonClick(Viewview){
- if(isSatellite==false){
- mapView.setSatellite(true);//卫星模式为True
- mapView.setTraffic(false);//交通模式为False
- mapView.setStreetView(false);//街景模式为False
- isSatellite=true;
- }else{
- mapView.setSatellite(false);
- isSatellite=false;
- }
- }
- });
- }
- @Override
- protectedbooleanisRouteDisplayed(){
- returnfalse;
- }
- }
更多相关文章
- Android获取本地图片之ACTION_GET_CONTENT与ACTION_PICK区别
- Android不错的图片压缩方法
- android之Matrix
- Android(安卓)利用Matrix实现图片随手指平移、旋转、缩放
- [Android]你不知道的Android进程化(3)--进程等级
- android小知识(1)
- Android百度地图之位置定位和附近查找代码简单实现 (上)
- Android设置拍照或者上传本地图片
- Android实现图片缩放与旋转