Reputation: 6246
I'm trying to override setOnMyLocationChangeListener on a SupportMapFragment using this
map.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
@Override
public void onMyLocationChange(Location location) {
LatLng you = new LatLng(location.getLatitude(), location.getLongitude());
float distanceTo = location.distanceTo(venueLocation);
String miles = metersToMiles(distanceTo);
dist.setText(miles + " miles away");
LatLngBounds.Builder builder = new LatLngBounds.Builder();
map.clear();
map.addMarker(new MarkerOptions()
.position(venue)
.title(centerName)
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.fu_map_marker)));
map.addMarker(new MarkerOptions()
.title("You are here")
.position(you));
builder.include(venue);
builder.include(you);
LatLngBounds bounds = builder.build();
map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 75));
}
});
Which kind of works, however, before the camera animates using the LatLngBounds, it automatically zooms to the users location and adds a blue dot. Is there anyway I can disable this?
Upvotes: 1
Views: 1379
Reputation: 73494
It is doing that because you have the My Location layer enabled. You can disabled it by
map.setMyLocationEnabled(false);
Also listening for Location changes that way is deprecated. There is a new Location api with the latest version of Google Play services that is supposed to provide the same functionality with less battery usage.
Upvotes: 1