2

这是代码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;
}
4

1 回答 1

0

最后,最重要的是将Google Play Services添加为 Android 库项目,如下所示:

  • 选择File > Import > Android > Existing Android Code Into Workspace,然后单击Next。选择Browse...,输入 */extras/google/google_play_services/libproject/google-play-services_lib*,然后单击Finish
  • 检查项目中是否存在包含libs/的文件夹android-support-v4.jar
  • android-support-v4.jar位于/extras/android/compatibility/v4/android-support-v4.jar您的“android-sdk”目录下。

在运行您的项目之前,您必须将您的项目构建目标设置为“Google APIs”,而不是 Android xx 版本:选择您的项目并单击Eclipse 中的Project > Properties > Project Build Target并选择任何“Google APIs”,然后运行您的项目在您的手机上。如果您使用模拟器,还必须将模拟器的 AVD 设置为任何“Google APIs”。

于 2013-04-18T05:45:57.323 回答