Reputation: 576
I have made a android application where I am showing current location of a user.
@Override
public void onLocationChanged(Location location) {
mLastLocation = location;
if (currLocationMarker != null) {
currLocationMarker.remove();
}
//Place current location marker
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_RED));
currLocationMarker = mGoogleMap.addMarker(markerOptions);
mGoogleMap.animateCamera( CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(),location.getLongitude()) , 6.0f) );
}
It gives me my current location with marker but problem is whenever I try to zoom out from the current location, within some seconds it focused again to the same location (Current) so I am not able to see my other points (Markers) on the map.
How to disable this auto zoom in feature in Google Maps?
Upvotes: 1
Views: 3659
Reputation: 1
Is your code called on onMapReady
method?
If not consider moving it there.
I think you are calling animateCamera
in onLocationChanged
and the code is called every time the location is updated and the map is re-focused to your location.
Upvotes: 0
Reputation: 510
Declare a global boolean flag
boolean isFisrtTime = true;
replace
mGoogleMap.animateCamera( CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(),location.getLongitude()) , 6.0f) );
with
if(isFisrtTime){
mGoogleMap.animateCamera( CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(),location.getLongitude()) , 6.0f) );
isFisrtTime = false; //this is will work at start only
}
Upvotes: 1
Reputation: 1376
you should use the animateCamera method for the first time only. You can use a boolean to call it once only. Declare a boolean globally and make it false and once this method is called turn it to true, before calling this cameraAnimate method check if the boolean was false then only to use it.
Upvotes: 1
Reputation: 18262
Center the camera on the current location only the first time:
private boolean firstLoad = true;
On your onLocationChanged
:
if (firstLoad) {
mGoogleMap.animateCamera( CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(),location.getLongitude()) , 6.0f) );
firstLoad = false;
}
Upvotes: 2