The Location-based services in android offers two APIs
1. Mapping
2. Location-based
Here we’ll talk about the first API i.e mapping
– The mapping package is com.google.android.maps
Things needed for android map
1. Internet connectivity – Since mapping APIs often reach across the internet to invoke services from Google servers.
– In manifest file add following line outside the application
<uses-permission android:name=”android.permission.INTERNET” />
2. To use google maps APIs services, you must agree Google Terms and condition, the terms will be presented to you when you sign up for a Map API Key.
Steps:
1. First Obtain a Maps API key from Google
– Find where your keychain is
* Go to Eclipse -> Preference -> Android -> Build
* see Defalt debug keystone – Here you see the keystore path
e.g: /Users/tech/.android/debug.keystore
* Go to the keystore location
* now run below command
$ keytool -list -keystore debug.keystore
* Now, paste your certificate’s MD5 fingerprint in the appropriate field on this Google site:
http://code.google.com/android/maps-api-signup.html
3. Add the following lines in manifest file within the application tag
<application>
<uses-library android:name=”com.google.android.maps”/>
</application>
4. extends MapActivity class
e.g
public class ActivityMap extends MapActivity
– MapActivity implements the following method.
@Override
protected boolean isRouteDisplayed() {
return false;
}
5. Understanding MapView and MapActivity
* Mapping technology in Android relies on the MapView UI control and an extension of android.app.Activity called MapActivity.
* The MapView and MapActivity classes take care of the heavy lifting when it comes to displaying and manipulation a map in Android.
* MapView need to instantiate it within a MapActivity, when instantiation a MapView, we need to supply the Maps API key
E.g:
If we instantiate a MapView using an XML layout, we need to set the android:apiKey property
<?xml version=”1.0″ encoding=”utf-8″?>
<com.google.android.maps.MapView
xmlns:android=”http://schemas.android.com/apk/res/android”
android:id=”@+id/mapview”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:clickable=”true”
android:apiKey=”Your Map Key”
/>