我检查我的logcat文件错误是位置manage is null
公共类MapsActivity扩展MapActivity { MapView mapView; MapController mc; GeoPoint 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(); // List 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
}
}
}
答案 0 :(得分:0)
您应该设置LocationListener(here)。在LocationListener的onLocationChanged方法中,只需让您的地图为更新后的位置设置动画。