How To Use Google Map V2 For Android -Part 1
Since Google Maps Android API as been officially deprecated as of December 3rd, 2012, We have to check Google Maps Android API v2 in detail.
For Documentation,please check https://developers.google.com/maps/documentation/android/intro
Main Features of Google Maps Android Api v2 :
The API allows you to add these graphics to a map:
- Icons anchored to specific positions on the map (Markers).
- Sets of line segments (Polylines) for drawing shapes.
- Enclosed segments (Polygons), filled, unfilled or hollow.
- Bitmap graphics anchored to specific positions on the map (Ground Overlays).
- Sets of images which are displayed on top of the base map tiles (Tile Overlays).
Inorder to Use this,we have to add Google Play Services as Library Project:It is inside our Android Sdk Folder-----
Step 1: Add Google play service as lib project.
android-sdk-folder>/extras/google/google_play_services/libproject/google-play-services_lib
Note: Download Google Play Services SDK for this.
Step 2:
Add "android-support-v4.jar" in our "libs" folder.
Step 3:
Login to Google Console using any Gmail account .
Step 4:
After Login ,Create a Project using the dropdown at the top left (Below "Google Apis" text).Then Move to "Services" section and activate "Google Maps Android API v2" and "Google Maps API v2".
Step 5:
After this, Select "API Access" and create key for android,For that we need SHA1
fingerprint and our project package name.This SHA 1 fingerprint is generated using the
command prompt.Once successfully placed these ,a new key will be generated as API Key.
How To Use this in Our Project?
Manifest File
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.trailmaster.app" android:versionCode="1" android:versionName="1.0" > <permission android:name=".permission.MAPS_RECEIVE" android:protectionLevel="signature" /> <uses-permission android:name="packagename.permission.MAPS_RECEIVE" /> <!-- Copied from Google Maps Library/AndroidManifest.xml. --> <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8" /> <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-feature android:glEsVersion="0x00020000" android:required="true" /> <application android:allowBackup="true" android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/AppTheme" > <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="XXXXXCMA8MyFORWXXXXXXXXXXXXXXXXXX" /> <activity android:name=".SampleActivity" android:label="@string/app_name" android:screenOrientation="portrait" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>packagename
In Main.xml:
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
In Our java Class:
public class SampleActivit extends android.support.v4.app.FragmentActivity {
private GoogleMap mMap;
private SupportMapFragment mMapFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setUpMapIfNeeded();
}
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the
// map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMapFragment = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map));
mMap = mMapFragment.getMap();
}
}
Stay Tuned For Part 2(CUSTOM TILE OVERLAY IN GOOGLE MAP)------Happy Coding!
1 comments:
good tutorial..