Reputation: 28519
I'm having awful problems with this. I have a MapView, in my activity I set the flag to show the zoom controls, and it works. But then the user navigates to another activity, comes back to the map, and the zoom controls have gone.
Is there a simple way to ensure the zoom controls are always present, or do I need to roll my own on top? Ideally I want to set up the zoom controls in a subclass of MapView to keep things simple. I suspect it's failing as the zoom controls are being set up at the wrong time, but when is the right time?
Upvotes: 4
Views: 347
Reputation: 2186
You can do it very easily.
On the onCreate()
method do:
MapView mapView = (MapView) findViewById(R.id.map_view_id);
mapView.setBuiltInZoomControls(true);
With that, the zoom buttons appear at the bottom of the screen. They disappear if now touch events occur for a small period of time and they appear automatically again if any touch events happens.
Upvotes: 0
Reputation: 9908
Here is what I do. First add a ZoomControl view to the file with your MapView (I am using a RelativeLayout to hold the MapView and ZoomControls)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<MapView
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="X"
android:clickable="true" />
<ZoomControls
android:id="@+id/zoomcontrols"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" />
</RelativeLayout>
Now in your onCreate method do something like
mapView.setBuiltInZoomControls(false);
ZoomControls zoomControls = (ZoomControls) findViewById(R.id.zoomcontrols);
zoomControls.setOnZoomInClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mapController.zoomIn();
}
});
zoomControls.setOnZoomOutClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mapController.zoomOut();
}
});
Upvotes: 3