Wednesday 6 February 2013

[Tutorial] Some Easy Steps For Google Map View Example For Android


Steps 1: OBTAIN 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 FOR GETTING GOOGLE API 



  1. Proceed to the location exactly where JDK installed.
  2. Certainly, there you will see KeyTool.
  3. Then simply Copy the path.
  4. Start a command prompt then change the directory to the keytool path.
  5. copy and paste the below code snippet to command prompt



keytool -list -alias androiddebugkey -keystore





  1. At this point we need to copy the path of the debug.keystore
  2. Head over to windows/users/[your computer user name]/.android/
  3. It’s simple to find the debug.keystore, so copy the path.
  4. 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.

https://developers.google.com/android/maps-api-signup



  1. Enter the Finger print using only number and digits. Stay away from including “:” .
  2. After that Tick the Agreement.
  3. 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.


  1. Start a Sample Project named GoogleMapDemo.





  1. Choose the Choose bulid SDK to Google API. I choosed Google API Level 16.
  2. Then Click Next for the rest, Finally press Finish.


  • Copy the below code to your Layout.

res/layout/activity_main.xml

<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>

NOTE: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.



Android Manifest.xml

<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




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. :)

src/com.example.androidmapviewdemo/AndroidMapViewDemo.java

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;
}

    
}






So now the map is shown but we can only pan/move the map. No other functionality like zooming, map the entered address, get address by simply touching on the map, drawing overlay to display some images to point out the selected locations and many interesting things we are going to do in our next tutorial.




YOU MAY ALSO LIKE::




Share This!


No comments:

Post a Comment

We are Happy to help you so we are given reply as soon as possible.
Thank You.

Increase Traffic By Click

Contact Form

Name

Email *

Message *

Powered By Blogger · Designed By Priyesh Marvi

Receive All Free Updates Via Facebook.