Search This Blog

Tuesday 8 May 2012

Google Map View




Google Map View

Google Maps library available for the Android developers helps you in creating own map viewing UIs.
Before start creating your Map Activity, some points should keep in mind.
ü    Check your SDK for Google Maps external library. This would be included with the Google APIs add-on. If not, install the same for the particular Android version you are using.
ü    Obtain an API Key for your application. Steps to obtain the API key is explained in another post.
ü    Create an AVD that uses the Google APIs as the deployment target.
ü    Access to the Internet should be there.

Start with the Map Activity creation:

Ø    Start a new project by selecting Google APIs as the target SDK.
Ø    Google Maps library is an external library and therefore it should be declared in the Android Manifest file.
Add this line as the child node of <application> tag.
<uses-library android:name="com.google.android.maps" />
Ø     Now request the Internet permission by inserting this line as the child of <manifest> tag.
<uses-permission android:name="android.permission.INTERNET" />
Ø    Avoid the title bar on your Map Activity by applying the theme inside the <activity> tag as android:theme="@android:style/Theme.NoTitleBar".
Ø    Then, open the main xml file and add com.google.android.maps.MapView as the root node.
The main.xml would be like this:
<?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 Maps API Key "
/>

Ø     Move to your Activity class and extends MapActivity from your activity.
Ø    Override isRouteDisplayed() method.
Ø    Inside the onCreate() method, set the zooming controls.

Complete source code of the class file is as follows:
public class MapExample extends MapActivity
{

 @Override
 protected void onCreate(Bundle icicle) {
  // TODO Auto-generated method stub
  super.onCreate(icicle);
  setContentView(R.layout.main);
  MapView mp=(MapView)findViewById(R.id.MapView);
  mp.setBuiltInZoomControls(true);
}

@Override
 protected boolean isRouteDisplayed() {
  // TODO Auto-generated method stub
  return false;
 }

}

No comments:

Post a Comment