Displaying different views in google map
In order to load Google map in your application,
1. Obtain Google map API key (how to obtain google api key )
2. Add permission on your manifest file to access internet
3. Add uses library in your manifest file for accessing Google Map
4. Extends MapActivity in your class (instead of Activity)
main.xml
<?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/mapView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:enabled="true" android:clickable="true" android:apiKey="0GSVI1mG2sQA6O0fc00gI7joiB0wht6l7Nv1_WA" /> </LinearLayout> |
MySampleMap.java
package com.example.googlemap; import android.os.Bundle; import com.google.android.maps.MapActivity; public class MySampleMap extends MapActivity{ @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); setContentView(R.layout.main); } @Override protected boolean isRouteDisplayed() { // TODO Auto-generated method stub return false; } } |
MapActivity Manifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.googlemap" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="8" /> <uses-permission android:name="android.permission.INTERNET"/> <application android:icon="@drawable/icon"android:label="@string/app_name"> <activity android:name=".MySampleMap" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <uses-library android:name="com.google.android.maps"/> </application> </manifest> |
Normally, google maps are loaded in the map mode. You can also display the map view in satellite mode by using the code
MapView mapView=(MapView)findViewById(R.id.mapview);
mapView.setSatellite(true) //to display map in satellite view
mapView.setStreetView(true) //to display main in street view
Comments
Post a Comment