我正在使用android模拟器,
一旦我运行应用程序,
它以正确的经度和纬度为中心,
但蓝点不在那里表示我当前的位置。
@Override
public void onMapReady(GoogleMap mGoogleMap) {
if (ActivityCompat.checkSelfPermission(Navi.this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(Navi.this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
this.gMap = mGoogleMap;
if (lat != 0.0 & lng != 0.0) {
if (this.gMap != null) {
this.gMap.setMyLocationEnabled(true);
this.gMap.getUiSettings().setMyLocationButtonEnabled(true);
this.gMap.getUiSettings().setCompassEnabled(true);
this.gMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
this.gMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(lat, lng)));
this.gMap.animateCamera(CameraUpdateFactory.zoomTo(14f));
}
} else {
if (this.gMap != null) {
LatLng latLng = new LatLng(14.6760, 121.0437);
this.gMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
this.gMap.animateCamera(CameraUpdateFactory.zoomTo(14f));
}
}
} else {
ActivityCompat.requestPermissions(Navi.this,
new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION},
MY_PERMISSIONS_REQUEST);
}
}
但是一旦我收到了新的经度和纬度, 出现蓝点。
private class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
lat = arg1.getDoubleExtra("lat", 0);
lng = arg1.getDoubleExtra("long", 0);
if (lat != 0.0 & lng != 0.0) {
if (gMap != null) {
if (ActivityCompat.checkSelfPermission(Navi.this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(Navi.this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
gMap.setMyLocationEnabled(true);
gMap.getUiSettings().setMyLocationButtonEnabled(true);
gMap.getUiSettings().setCompassEnabled(true);
gMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
gMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(lat, lng)));
gMap.animateCamera(CameraUpdateFactory.zoomTo(14f));
}
}
}
Log.e("LAT", "" + lat);
Log.e("LNG", "" + lng);
}
}
这个问题的原因是什么?