1

logcat ファイルのエラーを確認すると、場所の管理が null です

public class MapsActivity extends MapActivity { MapView mapView; MapController mc; ジオポイント p; double latPoint、lngPoint; LocationManager myManager;

/** 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.mapView);
    LinearLayout zoomLayout = (LinearLayout) findViewById(R.id.zoom);
    View zoomView = mapView.getZoomControls();

    zoomLayout.addView(zoomView, new LinearLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    mapView.displayZoomControls(true);

    mc = mapView.getController();
     LocationManager myManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    myManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,new myLocationListener());

    p = new GeoPoint((int) (latPoint * 1E6), (int) (lngPoint * 1E6));

    mc.animateTo(p);
    mc.setZoom(10);

    //---Add a location marker---

// MapOverlay mapOverlay = new MapOverlay(); // リスト listOfOverlays = mapView.getOverlays(); // listOfOverlays.clear(); // listOfOverlays.add(mapOverlay);

    mapView.invalidate();

}

@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}

class myLocationListener implements LocationListener {

    public void ListLocationUpdater() {
    }

    @Override
    public void onLocationChanged(Location loc) {
        if (myManager != null) {
            // List list = myManager.getAllProviders();
            String param = (String) myManager.getProviders(true).get(0);
            loc = myManager.getLastKnownLocation(param);
            if (loc != null) {
                latPoint = loc.getLatitude();
                lngPoint = loc.getLongitude();
                Log.e("RootDrawApplication",String.valueOf(latPoint)+"  , "+String.valueOf(lngPoint));

            } else
                Log.e("GoogleMaps ", "Error: Location  is null");
        } else
            Log.e("GoogleMaps ", "Error: Location Manager is null");
    }

    @Override
    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub

    }

}

}

4

1 に答える 1

0

LocationListener を設定する必要があります (ここ)。LocationListener の onLocationChanged メソッド内で、マップを更新された場所にアニメーション化するだけです。

于 2011-04-08T14:32:45.927 に答える