在我的应用程序中,我使用地图视图来定位我的 gps 位置。
如果我在启动应用程序之前打开 gps 并等待 gps 修复,所有工作最终都会成功。如果我在启动应用程序后打开 gps,则会出现问题,因为在地图中该位置不会出现。
这是我在 MapActivity 上的代码:
private MapView mapView;
private List<Overlay> mapOverlays;
private MapController mapController;
private LocationManager locationManager;
private MyLocationOverlay myLocationOverlay;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map_sensor);
// Configure the Map
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapView.setSatellite(false);
mapController = mapView.getController();
GeoPoint point = new GeoPoint(47.6945683 *1E6 ,11.5765886 *1E6);
mapController.animateTo(point);
mapController.setZoom(9); // Zoom 1 is world view
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
50, new GeoUpdateHandler());
myLocationOverlay = new MyLocationOverlay(this, mapView);
mapView.getOverlays().add(myLocationOverlay);
mapOverlays = mapView.getOverlays();
}
public class GeoUpdateHandler implements LocationListener {
@Override
public void onLocationChanged(Location location) {}
@Override
public void onProviderDisabled(String provider) {}
@Override
public void onProviderEnabled(String provider) {}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {}
}
我错过了什么?