views:

570

answers:

5

would like to add a zoom control to the map. I also want to layout the position of the zoom Control instead of the default middle bottom position. I can do this by getZoomControl but it is deprecated.

Could anyone tell me how to do this with setBuildtInZoomControls?

A: 

I'm pretty sure that the only way to do this is to either use the MapView's deprecated getZoomControls() or to DIY it. The MapController has the methods necessary (e.g. zoomIn() and zoomOut()).

fiXedd
A: 

So anyone has an answer for this ?

Pedro Teixeira
+1  A: 
mapView.getZoomButtonsController()

Although this is undocumented (at least in the javadoc available here: com.google.android.maps) I am quite sure this is the replacement for the deprecated getZoomControls

Edit: just found out that it is documented, just not in the google api docs but rather here: ZoomButtonsController on developer.android.com

You could then call getContainer () or getZoomControls () (depending on what you want to do) to get access to the zoom controls view.

And then do something like

RelativeLayout.LayoutParams zoomParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
zoomParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
mapView.getZoomButtonsController().getZoomControls().setLayoutParams(zoomParams);

although I have to admit that I am not sure what layout the maps view uses, could be LinearLayout as well.

slup
+1  A: 

This is how I got mine working finally (by embedding a ZoomControl in XML layout).

mapView = (MapView) this.findViewById(R.id.mapView);

ZoomControls zoomControls = (ZoomControls) findViewById(R.id.zoomcontrols);
zoomControls.setOnZoomInClickListener(new OnClickListener() {
        public void onClick(View v) {
            mapView.getController().zoomIn();
        }
});
zoomControls.setOnZoomOutClickListener(new OnClickListener() {
        public void onClick(View v) {
            mapView.getController().zoomOut();
        }
});

See: http://stackoverflow.com/questions/920741/always-show-zoom-controls-on-a-mapview

duskstriker
A: 
RelativeLayout relativeLayout = new RelativeLayout(this);
setContentView(relativeLayout);

final MapView mapView = new MapView(this, DEBUG_MAP_API_KEY);
RelativeLayout.LayoutParams mapViewLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT,RelativeLayout.LayoutParams.FILL_PARENT );
relativeLayout.addView(mapView, mapViewLayoutParams);

RelativeLayout.LayoutParams zoomControlsLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT );
zoomControlsLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
zoomControlsLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);

relativeLayout.addView(mapView.getZoomControls(), zoomControlsLayoutParams);

mapView.setClickable(true);
mapView.setEnabled(true);

I think this should work ... Hope this is useful :)

ravi
This also uses the deprecated getZoomControls functions of the mapview.
Janusz