maps in android
TRANSCRIPT
MAPS IN ANDROID
By- Sumita Das
Created by Sumita Das
Android allows us to integrate Google maps in our application.
Customize the map according to your choices.
Introduction
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.
Introducing Map View and Map Activity
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. .
Getting Your Maps API Key
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.
Creating a Map-Based Activity
<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.
Creating a Map-Based Activity
<uses-permission android:name=”android.permission.INTERNET”/>
Created by Sumita Das
A map Activity layout resource<?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
Framework for creating a new map-based Activity.
import com.google.android.maps.MapActivity; // import classesimport 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
Example of a basic map-based Activity
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();
Configuring and Using Map Views
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.