2
這是代碼Google Map Android API v1
。我不知道轉換爲API v2
。請幫幫我!將Google地圖Android API v1中的代碼轉換爲Google地圖Android 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;
}
非常感謝你。但是,你在上面指導的一切,我做了。但是,MapView顯示爲空。 :-( – 2013-04-18 06:09:01
我用真實設備測試應用程序,我認爲這是因爲代碼 – 2013-04-18 06:19:10
,所以它可能是空白的,因爲API密鑰錯誤,Mapview使用MD5指紋,Maps v2需要SHA指紋,使用keytool命令獲取它或使用代碼(它在這裏的答案:http://stackoverflow.com/questions/13966906/app-is-misconfigured-for-facebook-login-not-returning-the-logcat-after-setti) – Analizer 2013-04-18 06:43:45