我想在地圖上顯示當前位置,但onLocationChanged沒有被調用。onLocationChanged沒有被調用
@Override
public void onLocationChanged(Location location) {
Log.d("Called", "onLocationChanged");
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title("Current Position");
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA));
mMap.addMarker(markerOptions);
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(11));
}
這裏是我的onCreate代碼
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, this);
您是否啓用了位置? – Pehlaj
是的,位置已啓用,並且還請求獲得許可 – A1H1