2017-04-06 84 views
0

我想在地圖上顯示當前位置,但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); 
+0

您是否啓用了位置? – Pehlaj

+0

是的,位置已啓用,並且還請求獲得許可 – A1H1

回答

0

你們有這兩種權限

requestPermissions({ 
     android.Manifest.permission.ACCESS_FINE_LOCATION, 
     android.Manifest.permission.ACCESS_COARSE_LOCATION, 
    }, REQUESTPERM); 

,並覆蓋onRequestPermissionsResult處理批/拒絕?

@Override 
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {} 
+0

已經嘗試過此 – A1H1

+0

@ A1H1,發佈您的代碼 – Vyacheslav

+0

這裏是我的活動 https://justpaste.it/158p4 – A1H1

相關問題