Using the Map Controller

Use the Map Controller to pan and zoom a MapView. You can get a reference to a MapView's controller usinggetController.

MapController mapController = myMapView.getController();

Map locations in the Android mapping classes are represented by GeoPoint objects, which contain latitude and longitude measured in microdegrees. To convert degrees to microdegrees, multiply by 1E6 (1,000,000).

Before you can use the latitude and longitude values stored in the Location objects returned by location-based services, you'll need to convert them to microdegrees and store them as GeoPoints.

Double lat = 37.422006*1E6; Double lng = -122.084095*1E6;

GeoPoint point = new GeoPoint(lat.intValue(), lng.intValue());

Re-center and zoom the Map View using the setCenter and setZoom methods available on the Map View'sMapController.

mapController.setCenter(point); mapController.setZoom(l);

When you are using setZoom, 1 represents the widest (or most distant) zoom and 21 the tightest (nearest) view.

FIGURE 8-4

The actual zoom level available for a specific location depends on the resolution of Google's maps and imagery for that area. You can also use zoomIn and zoomOut to change the zoom level by one step.

The setCenter method will''jump'' to a new location; to show a smooth transitionanimateTo.

mapController.animateTo(point);

Mobile Apps Made Easy

Mobile Apps Made Easy

Quick start guide to skyrocket your offline and online business success with mobile apps. If you know anything about mobile devices, you’ve probably heard that famous phrase coined by one of the mobile device’s most prolific creators proclaiming that there’s an app for pretty much everything.

Get My Free Training Guide


Post a comment