2

This is code Google Map Android API v1. I don't know convert to API v2. Help me, please!

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;
}
Renjith
  • 5,783
  • 9
  • 31
  • 42
Optimus NTL
  • 124
  • 10

1 Answers1

0

Finally, the most important is to add Google Play Services as an Android library project as follows:

  • Select File > Import > Android > Existing Android Code Into Workspace and click Next. Select Browse..., enter */extras/google/google_play_services/libproject/google-play-services_lib*, and click Finish.
  • Check if the libs/ folder containing the android-support-v4.jar exists in your project.
  • android-support-v4.jar is located in /extras/android/compatibility/v4/android-support-v4.jar under your "android-sdk" drectory.

Before running your project, you must set your project Build target to "Google APIs", not Android x.x. version : Select your project and click Project > Properties > Project Build Target in Eclipse and select any "Google APIs ", and then run your project on your phone. If you use the emulator, also must set the AVD of the emulator to the any "Google APIs ".

JJD
  • 50,076
  • 60
  • 203
  • 339
kyogs
  • 6,766
  • 1
  • 34
  • 50
  • Thanks you very much. But everything which you guide above that I done. However, MapView shows empty. :-( – Optimus NTL Apr 18 '13 at 06:09
  • it's probably blank because of the wrong API key. Mapview uses MD5 fingerprint, Maps v2 needs SHA fingerprint, use keytool command to obtain it, or use code (it's in the answer in here: http://stackoverflow.com/questions/13966906/app-is-misconfigured-for-facebook-login-not-returning-the-logcat-after-setti) – Analizer Apr 18 '13 at 06:43