package my.android.MyMap; 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.MyLocationOverlay; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MyMap extends MapActivity { MapView mapView; MapController mapController; boolean isSatellite = false; MyLocationOverlay overlay; /** 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); mapController = mapView.getController(); mapController.setZoom(15); updateView(); } @Override protected boolean isRouteDisplayed() { // TODO Auto-generated method stub return false; } private void updateView(){ Double lat = 31.23717*1E6; Double lng = 121.50811*1E6; GeoPoint point = new GeoPoint(lat.intValue(), lng.intValue()); mapController.setCenter(point); // 放大地图,缩放等级加 Button btnZoomIn = (Button) findViewById(R.id.zoomin); btnZoomIn.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { mapController.setZoom(mapView.getZoomLevel() + 1); } }); // 缩小地图,缩放等级减 Button btnZoomOut = (Button) findViewById(R.id.zoomout); btnZoomOut.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { mapController.setZoom(mapView.getZoomLevel() - 1); } }); // 缩小地图,缩放等级减 Button btnSatellite = (Button) findViewById(R.id.satellite); btnSatellite.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { if (isSatellite == false) { mapView.setSatellite(true); //卫星模式为True mapView.setTraffic(false); //交通模式为False mapView.setStreetView(false); //街景模式为False isSatellite = true; } else { mapView.setSatellite(false); isSatellite = false; } } }); } } <?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="0tUPgBSwSfaiF6skJcskb58zuzkih2_bz2oYV0A" android:clickable="true" /> <Button android:id="@+id/zoomin" android:text="@string/in" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" /> <Button android:id="@+id/zoomout" android:text="@string/out" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" /> <Button android:id="@+id/satellite" android:text="@string/oth" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" /> </RelativeLayout> <?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">Hello World, MyMap!</string> <string name="app_name">MyMap</string> <string name="in">in</string> <string name="out">out</string> <string name="oth">oth</string> </resources> <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="my.android.MyMap" android:versionCode="1" android:versionName="1.0"> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.INTERNET"/> <application android:icon="@drawable/icon" android:label="@string/app_name"> <uses-library android:name="com.google.android.maps"/> <activity android:name=".MyMap" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>