How to use meters value in zoom level in google ma

2019-07-29 23:35发布

问题:

Previously I used zoom level in google maps by hardcoding. But now it comes from response.

So how to convert the meters by passing into zoom level? In my code, I am displaying a big circle icon and also points. So for both, I use hardcoded zoom level. But now it comes from response.

LatLng retailerPosition = new LatLng(Double.parseDouble(retailerLatitude), Double.parseDouble(retalerLongitude));
    mMap.addMarker(new MarkerOptions().position(retailerPosition).title("").icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_circle_red)));
    mMap.moveCamera(CameraUpdateFactory
            .newLatLngZoom(retailerPosition, 3)); //3 hardcoded one. 

for (int i = 0; i < listLocation.size(); i++) {
            LatLng sitePosition = new LatLng(Double.parseDouble(listLocation.get(i).getRetLatitude()), Double.parseDouble(listLocation.get(i).getRetLongitude()));
            mMap.addMarker(new MarkerOptions().position(sitePosition).title("").icon(BitmapDescriptorFactory.fromResource(R.drawable.round)));
            mMap.moveCamera(CameraUpdateFactory
                    .newLatLngZoom(sitePosition, 3)); //3 hardcoded one
        }

3 is hardcoded one. But now it comes from response.

"range": "1000" //this comes in response as "meters"

So how to apply this in above logic to convert from meters to zoom level?

回答1:

  1. Please add this Map Utils library:

compile 'com.google.maps.android:android-maps-utils:0.4.3'

  1. Source code to convert: