2017-04-06 57 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

相关问题