Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting max zoom level in google maps android api v2

I'm currently working on developing apps by using Google maps android API v2. My code is as follows. Suppose map has several markers and zoom up to show all markers in display.

LatLngBuilder.Builder builder = LatLngBounds.builder(); for(Marker m : markers){     builder.include(m.getPosition()); } LatLngBounds bounds = builder.build(); map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 10); 

This code is working fine but I want to stop animating when the zoom level reached to 17.0f; It seems map API does not have such method to control zoom level. Does anybody know any idea to solve this problem?

like image 568
user2223820 Avatar asked Mar 29 '13 09:03

user2223820


People also ask

How do I set Google Maps to max zoom?

Setting up the minimum or maximum Zoom value for Google Maps can be done by adding the shortcode attribute with Store Locator Shortcode. Furthermore, the maximum value of Google Maps Zoom level is 22. Therefore, the defined maximum value must be below or equal to 22, which is the default.

How do I custom zoom on Google Maps?

You can change the zoom level of the map using simple steps. Step 1 Go to Add or Edit Map page . Step 2 Select 'Default zoom level' in the 'Map Information section'. Step 3 click save map and see the changes.


2 Answers

A recent update to the Google Maps API introduces the functions you require:

GoogleMap.setMaxZoomPreference()  GoogleMap.setMinZoomPreference() 

It still does not prevent the animation from playing, though.

like image 173
Dmitry Serov Avatar answered Sep 18 '22 00:09

Dmitry Serov


I have not found any direct solution in the Google Maps API. A potential solution to this problem consists in listening against the OnCameraChange event: Whenever this event triggers and the zoom level is above the maximum zoom level, it is possible to call animateCamera(). The resulting code would be the following:

@Override public void onCameraChange(CameraPosition position) {     float maxZoom = 17.0f;     if (position.zoom > maxZoom)         map_.animateCamera(CameraUpdateFactory.zoomTo(maxZoom)); } 
like image 42
Tisys Avatar answered Sep 20 '22 00:09

Tisys