我可以在移动标记上显示纬度和经度。当此onMapReady
调用时,纬度和经度设置为zero
。
以下是代码:
public void onMapReady(GoogleMap googleMap) {
Log.d(TAG, "OnMapReady");
mMap = googleMap;
mMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition cameraPosition) {
Log.d("Camera postion change" + "", cameraPosition + "");
mCenterLatLong = cameraPosition.target;
mMap.clear();
try {
Location mLocation = new Location("");
mLocation.setLatitude(mCenterLatLong.latitude);
mLocation.setLongitude(mCenterLatLong.longitude);
startIntentService(mLocation);
mLocationMarkerText.setText("Lat : " + mCenterLatLong.latitude + "," + "Long : " + mCenterLatLong.longitude);
} catch (Exception e) {
e.printStackTrace();
}
}
});
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
}
我想在我打开应用程序时设置-34, 151
lat和long,否则我想在应用程序打开时获取当前位置。我怎样才能做到这一点?
答案 0 :(得分:1)
您可以在onMapReady(GoogleMap googleMap)
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(-34, 151))
.zoom(13) //optional if you want to zoom or not
.build();
MapFragment.newInstance(new GoogleMapOptions()
.camera(cameraPosition));
要获取地图上的当前位置,请检查此answer
答案 1 :(得分:1)
在onMapReady(GoogleMap googleMap)
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-34, 151), 12.0f));