MapView Basics

Email In PDF.

MapView is the View used to display Maps in Android. This guide will help you get started with building Map based apps. The code is pretty basic, just opens a MapView and allows to move around.

 

First, couple of things to be added to the manifest file. Using MapViewrequires permission to use the Internet.

Since com.google.mapsis not a standard package in the Android library, we have to explicitly add it.

public class Mapping extends MapActivity { private MapView map; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); map = new MapView(this, "apikey");

To use the MapView, we have to extend the MapActivity class. It manages the lifecycle and background processes of MapView.

MapView can be created either by using its contructor or by inflating the view from the layout XML. Here, the contructor is used.

MapView constructor takes two parameters, context of the View and the Developer API Key. The key can be any string value as of now.

setContentView(map); map.setEnabled(true); map.setClickable(true); GeoPoint p = new GeoPoint((int)(19.084182 * 1000000), (int)(72.855835 * 1000000));

GeoPointclass stores the latitude/longitude value pair.

MapController mc = map.getController(); mc.animateTo(p); mc.setZoom(12); map.setSatellite(true); MapControlleris for controlling the map to do stuff like panning and zooming.

animateTo()will move the map to the given point. setZoom()allows to zoom into the map from level 1 to 21. setSatellite()will enable the satellite view of the location as seen below,

 

Image:map2.png ______________________________

Theo gphone

Comments (0)Add Comment

Write comment

security code
Write the displayed characters


busy

Tin liên quan:
Tin mới hơn:
Tin cũ hơn: