Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is google maps not zooming on the Lat/Long I provide?

I have implemented the Google Maps API v2 in my Android app. I add a marker and zoom to level 14 when I open the activity containing the map fragment.

Here is how I add/update the marker:

private void updateMarker() {
    if(marker != null){
        marker.remove();
    }
    LatLng latlng = new LatLng(Double.parseDouble(latitude), Double.parseDouble(longitude));
    marker = mMap.addMarker(new MarkerOptions().position(latlng).title(username));
    marker.setIcon((BitmapDescriptorFactory.fromResource(R.drawable.marker)));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(latlng));
    mMap.animateCamera(CameraUpdateFactory.zoomTo(zoom), 2000, null);
}

It works correctly in debug via Android Studio, using a Nexus 5 with the latest Android installed. The problem is when I run a release build. The marker is added in the correct place, the zoom animation works correctly, zooming to the correct level. But it doesn't move to the marker I added.

like image 560
crmepham Avatar asked Feb 07 '23 16:02

crmepham


2 Answers

Use this

mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, zoom));

Or

 mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latlng, zoom), 2000, null);

Don't call both method right after each other.

like image 88
Vipin Sharma Avatar answered Feb 11 '23 01:02

Vipin Sharma


you should pass the result value of CameraUpdateFactory.newLatLngZoom(latlng, zoom) to animateCamera which returns a CameraUpdate that moves the center of the screen to a latitude and longitude specified by a LatLng object, and moves to the given zoom level. You can read more about it here

like image 23
Blackbelt Avatar answered Feb 11 '23 00:02

Blackbelt