shkschneider
shkschneider

Reputation: 18243

MapActivity - How to restrict zoom levels?

I implemented a MapActivity with Pins on it, following HelloMapView Tutorial and many StackOverflow resources.

For the purpose of my app, I would like to limit the zoom levels with a minimum and a maximum. In fact I would like to avoid using android:clickable="true" on my MapView.

I could not find how do achieve that.

AndroidManifest.xml

<uses-sdk
    android:maxSdkVersion="16"
    android:minSdkVersion="7"
    android:targetSdkVersion="15" />

MyMapActivity.java

// Here is my MapView
mMapView = (MapView) findViewById(R.id.game_map);
mMapView.setBuiltInZoomControls(false);
mMapView.setSatellite(true);
mMapController = mMapView.getController();
mMapController.setZoom(CONST_MAP_ZOOM);
mMapController.setCenter(new GeoPoint(48856700, 2351000));
mMapController.animateTo(new GeoPoint(48856700, 2351000));

But when I use fingers, I can zoom out until I see the whole planet.

What I would like would be to limit the zoom levels.

Upvotes: 2

Views: 868

Answers (2)

shkschneider
shkschneider

Reputation: 18243

I found a way out.

I disable multi-touche on the MapView:

<com.google.android.maps.MapView
    android:id="@+id/game_map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:apiKey="@string/google_maps_api_key"
    android:clickable="true" />

Then I hide zoom controls:

mMapView = (MapView) findViewById(R.id.game_map);
mMapView.setBuiltInZoomControls(false);

Then I implement my own zoom controls.

Upvotes: 0

Frank Sposaro
Frank Sposaro

Reputation: 8531

MapView does have on onSizeChanged

see https://developers.google.com/maps/documentation/android/reference/com/google/android/maps/MapView#onSizeChanged(int, int, int, int)

Perhaps you could listen for that and then call getZoomLevel() and see if it's in your acceptable range and change it from there.

Or better yet, you could override the onDraw and always check it there. Set minimum zoom level for MapView

Upvotes: 1

Related Questions