在我的應用程序中,我使用地圖視圖可以找到我的GPS位置。Android:谷歌地圖,我的gps位置不顯示,如果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) {}
}
我錯過了什麼?
更確切地說,我應該怎麼做才能觸發locationListener? – lory105
再次需要請求位置更新,如answer(locationManager.requestLocationUpdates(...))所示 – Braj