Step 1 : Obtaining Google API Key
To make use of Google Map or any other Google API you need to have a Google API key.It is extremely easy to get a Google API Key. You see below I have made a Video which is made up of step-by-step procedure for obtaining the Google API key.
Detailed Steps
- Proceed to the location exactly where JDK installed.
- Certainly, there you will see KeyTool.
- Then simply Copy the path.
- Start a command prompt then change the directory to the keytool path.
- copy and paste the below code snippet to command prompt
keytool -list -alias androiddebugkey -keystore
- At this point we need to copy the path of the debug.keystore
- Head over to windows/users/[your computer user name]/.android/
- It’s simple to find the debug.keystore, so copy the path.
- Next paste the keystore path surrounded with “” combined with the step 5 code snippet.
keytool -list -alias androiddebugkey -keystore "C:.android.keystore" -storepass android -keypass android
- Last but not least press Enter. You will notice the Certificate Finger Print.
- At this moment visit this link to sign up to Google API.
- Enter the Finger print using only number and digits. Stay away from including “:” .
- After that Tick the Agreement.
- Simply click Generate API key. You should see the API key now. Copy the actual URL intended for future reference.
Step 2 : Hands-on Google Map in Emulator
Before start to code our Google Map Alert App, we are now going to test it, to ensure we are ready to go.- Start a Sample Project named GoogleMapDemo.
- Choose the Choose bulid SDK to Google API. I choosed Google API Level 16.
- Then Click Next for the rest, Finally press Finish.
- Copy the below code to your Layout.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.google.android.maps.MapView
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:apiKey="06Q7KxHWP0w3-i0IpzRr8sSRnDLyHWAfJ_lk8mQ" />
</RelativeLayout>
Here you should enter your apikey otherwise it won’t work.
- Ok in case you are so curious, then simply run it. You will find the below stopped message.
Just what exactly is the mistake we certainly have done. We have setup every little thing as well as enter the MapView component within our layout.
But It is not sufficient to really make it do the job. We have seen lots of android tutorial for beginners. Therefore by now you should capable of finding out, exactly what do we have to do in order to succeed.
Absolutely yes, you are right, we should tell to the Manifest file that we are going to make use of Google Map for this application, and also Internet access.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.googlemapdemo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/google_map_demo" >
<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>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
Do you believe that this time, it’s going to run the app and show the map.
I am not going to say anything at the moment, just proceed as well as run the project.
I am not going to say anything at the moment, just proceed as well as run the project.
So above is the answer. So for we have extends only Activity, but in order to make use of Google Map, Our Java Code should extends MapActivity.
- Then finally include the unimplemented methods.
package com.example.googlemapdemo;
import com.google.android.maps.MapActivity;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
public class MainActivity extends MapActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
No comments:
Post a Comment