MAPS IN ANDROID
By-
Sumita Das
 Android allows us to integrate Google maps in our application.
 Customize the map according to your choices.
Created by Sumita Das
Several classes that are used to support Android maps:
 MapView: User interface element that displays the map.
 MapActivity: Base class used to create an Activity that can include
a Map View.
 Overlay: Class used to annotate your maps
 MapController: Used to control the map, and enables the user to set
the center location and zoom levels.
 MyLocationOverlay: Can be used to display the current position
and orientation of the device.
Created by Sumita Das
 Obtain an API key from the Android developer website at
http://code.google.com/android/maps-api-signup.html.
 To obtain a key, you need to specify the MD5 fingerprint of
the certificate used to sign your application. .
Created by Sumita Das
 To use maps- extend MapActivity.
 The layout for the new class must then include a MapView to
display a Google Maps interface element.
 Android maps library - optional API.
 So it must be explicitly included in the application manifest
before it can be used.
<uses-library
android:name=”com.google.android.maps”/>
Created by Sumita Das
 Map View :
-Downloads its map tiles on demand
- Any application that features a Map View needs to include a
uses-permission for Internet access.
 Add a uses-permission tag to your application manifest for
INTERNET, as shown here:
 After adding the library and configuring your permission,
you’re ready to create your new map-based Activity.
<uses-permission
android:name=”android.permission.INTERNET”/>
Created by Sumita Das
<?xml version=”1.0” encoding=”utf-8”?>
<LinearLayout
xmlns:android=”http://schemas.android.com/apk/res/android”
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”>
<com.google.android.maps.MapView
android:id=”@+id/map_view”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:enabled=”true”
android:clickable=”true”
android:apiKey=”mymapapikey”/>
</LinearLayout>
Created by Sumita Das
import com.google.android.maps.MapActivity; // import classes
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import android.os.Bundle;
public class MyMapActivity extends MapActivity
{
private MapView mapView;
private MapController mapController;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_layout);
mapView = (MapView)findViewById(R.id.map_view);
}
@Override
protected boolean isRouteDisplayed() {
// IMPORTANT: This method must return true if your Activity is displaying
driving directions. Otherwise return false.
return false;
}} Created by Sumita Das
Created by Sumita Das
1. To display a satellite view and the expected traffic overlay:
mapView.setSatellite(true);
mapView.setTraffic(true);
2. To find the current and maximum available zoom levels:
int maxZoom = mapView.getMaxZoomLevel();
int currentZoom = mapView.getZoomLevel();
Created by Sumita Das
3. To obtain center point and currently visible longitude and
latitude span (in decimal degrees).
GeoPoint center = mapView.getMapCenter();
int latSpan = mapView.getLatitudeSpan();
int longSpan = mapView.getLongitudeSpan();
Created by Sumita Das
[1]Wei-Meng Lee, “Beginning Android
Application Development”, Wiley Publishing
Inc.
Created by Sumita Das

Maps in android

Editor's Notes

  • #3  Show any location on the map , or show different routes on the map. Map Views offer full programmatic control of the map display, letting you control the zoom, location, and display modes including the option to display a satellite view
  • #5 To use a Map View in your application, you must first Without an API key the Map View cannot download the tiles used to display the map.