这是代码Google Map Android API v1
。我不知道转换为API v2
. 请帮帮我!
FlatBack.java
public class FlatBack extends MapActivity {
private MapView mapView;
private MyLocationOverlay myLocationOverlay;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
mapView = (MapView) findViewById(R.id.mapView);
mapView.setBuiltInZoomControls(true);
myLocationOverlay = new FixLocation(this, mapView);
mapView.getOverlays().add(myLocationOverlay);
mapView.postInvalidate();
zoomToMyLocation();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.map_toggle, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.map:
if (mapView.isSatellite() == true) {
mapView.setSatellite(false);
mapView.setStreetView(true);
}
return true;
case R.id.sat:
if (mapView.isSatellite() == false) {
mapView.setSatellite(true);
mapView.setStreetView(false);
}
return true;
case R.id.both:
mapView.setSatellite(true);
mapView.setStreetView(true);
default:
return super.onOptionsItemSelected(item);
}
}
@Override
protected void onResume() {
super.onResume();
myLocationOverlay.enableMyLocation();
}
@Override
protected void onPause() {
super.onPause();
myLocationOverlay.disableMyLocation();
}
private void zoomToMyLocation() {
GeoPoint myLocationGeoPoint = myLocationOverlay.getMyLocation();
if (myLocationGeoPoint != null) {
mapView.getController().animateTo(myLocationGeoPoint);
mapView.getController().setZoom(10);
}
}
protected boolean isRouteDisplayed() {
return false;
}