Android Maps

查了不少网址终于把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源代码
  1. package com.chen;
  2. import android.os.Bundle;
  3. import android.view.View;
  4. import android.widget.Button;
  5. import com.google.android.maps.GeoPoint;
  6. import com.google.android.maps.MapActivity;
  7. import com.google.android.maps.MapController;
  8. import com.google.android.maps.MapView;
  9. public class BasicMapApp extends MapActivity {
  10.     MapView mapView; 
  11.     MapController mapController; 
  12.     boolean isSatellite = false;
  13.     @Override 
  14.     public void onCreate(Bundle icicle) { 
  15.         super.onCreate(icicle); 
  16.         setContentView(R.layout.main); 
  17.         mapView = (MapView) findViewById(R.id.map); 
  18.         mapController = mapView.getController(); 
  19.         mapController.setZoom(15); 
  20.         updateView(); 
  21.     } 
  22.     
  23.     private void updateView(){ 
  24.         Double lat = 31.23717*1E6; 
  25.         Double lng = 121.50811*1E6; 
  26.         GeoPoint point = new GeoPoint(lat.intValue(), lng.intValue()); 
  27.         mapController.setCenter(point); 
  28.         
  29.         // 放大地图,缩放等级加
  30.         Button btnZoomIn = (Button) findViewById(R.id.zoomin);
  31.         btnZoomIn.setOnClickListener(new View.OnClickListener() {
  32.             public void onClick(View view) {
  33.                 mapController.setZoom(mapView.getZoomLevel() + 1);
  34.             }
  35.         });
  36.         
  37.         // 缩小地图,缩放等级减
  38.         Button btnZoomOut = (Button) findViewById(R.id.zoomout);
  39.         btnZoomOut.setOnClickListener(new View.OnClickListener() {
  40.             public void onClick(View view) {
  41.                 mapController.setZoom(mapView.getZoomLevel() - 1);
  42.             }
  43.         });
  44.         
  45.         // 缩小地图,缩放等级减
  46.         Button btnSatellite = (Button) findViewById(R.id.satellite);
  47.         btnSatellite.setOnClickListener(new View.OnClickListener() {
  48.             public void onClick(View view) {
  49.                 if (isSatellite == false) {
  50.                     mapView.setSatellite(true); //卫星模式为True
  51.                     mapView.setTraffic(false); //交通模式为False
  52.                     mapView.setStreetView(false); //街景模式为False
  53.                     isSatellite = true;
  54.                 } else {
  55.                     mapView.setSatellite(false);
  56.                     isSatellite = false;
  57.                 }
  58.             }
  59.         });
  60.     } 
  61.     
  62.     @Override
  63.     protected boolean isRouteDisplayed() {
  64.         return false;
  65.     }
  66. }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值