Building Google Map Based Applications on Android Tablet Device with Google Map API


Developing Google Map based application on Android Tablet applications is pretty easy with the help of Google Map API Key.

To start for developing application for Google Map with Android device , First start with Eclipse & locate your debug.keystore file from Window-> Preference-> Android->Build .

Then , find your MD5 key from Keytool.exe(Available in JDK/JRE folder in Program Files) for Google MAP API Key:  http://code.google.com/android/add-ons/google-apis/mapkey.html  & Run the following command in command prompt:

keytool.exe -list -alias androiddebugkey -keystore

“C:\Users\<username>\.android\debug.keystore” -storepass android

-keypass android

 

Next , go to  http://code.google.com/android/maps-api-signup.html & paste the MD5 Key to find your Google Map API Key.

Source Code Design:

Locations.java:

package com.example.LBS;

import android.app.ListFragment;

import android.os.Bundle;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

import android.widget.*;

import android.widget.ArrayAdapter;

import android.widget.ListView;

import android.widget.Toast;

public class Locations extends ListFragment{

String[] locations = {

“Grand Canyon,Arizona(Valley)”,

“Bill Gates’ house”,

“Yosemite National Park,California (Park)”,

};

String[] latlng = {

“36.1125,-113.995833”,

“47.627787,-122.242135”,

“36.849722,-119.5675”,

};

@Override

publicvoid onCreate(Bundle savedInstanceState){

super.onCreate(savedInstanceState);

// — Displays the list of locations in the list

setListAdapter(new ArrayAdapter<String>(getActivity(),

android.R.layout.

simple_list_item_1,locations));

}

public void onListItemClick(ListView parent,View v,

int position,long id)

{

Toast.makeText(getActivity(),

“You have selected” + locations[position],

Toast.LENGTH_SHORT).show();

}

@Override

public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){

return inflater.inflate(R.layout.locations, container,false);

}

}

Next Code for ShowMap.java:

package com.example.LBS;

import android.app.Fragment;

import android.os.Bundle;

import android.view.LayoutInflater;

import android.view.Menu;

import android.view.MenuItem;

import android.view.MenuInflater;

import android.view.View;

import android.view.ViewGroup;

import android.widget.Toast;

import  com.google.android.maps.GeoPoint;

import com.google.android.maps.MapController;

import com.google.android.maps.MapView;

public class ShowMap extends Fragment

{

private MapView mapView;

private MapController mc;

@Override

public View onCreateView(LayoutInflater inflater,

   ViewGroup container,Bundle savedInstanceState)

   {

return inflater.inflate(R.layout.showmap,container,false);

   }

// Displaying Zoom Control on Map

publicvoid onStart() {

super.onStart();

mapView = (MapView)getActivity().findViewById(R.id.mapView);

mapView.setBuiltInZoomControls(true);

mc = mapView.getController();

//mc.zoomIn();

//mc.zoomOut();

mapView.setSatellite(true);

   }

}

Next , Insert locations.xml & showmap.xml in res/layout folder:

<?

xmlversion=“1.0”encoding=“utf-8”?>

<

LinearLayoutxmlns:android=http://schemas.android.com/apk/res/android&#8221;

android:layout_width=“fill_parent”

android:layout_height=“fill_parent”

android:orientation=“vertical”>

<TextView

android:layout_width=“fill_parent”

android:layout_height=“wrap_content”

android:text=“List of Locations”

android:textSize=“30sp”

android:textColor=“#adff2f”       

/>

<ListView 

android:id=“@id/android:list”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:layout_weight=“1”

android:drawSelectorOnTop=“false”/>

</

LinearLayout>

showmap.xml:

<?

xmlversion=“1.0”encoding=“utf-8”?>

<

LinearLayoutxmlns:android=http://schemas.android.com/apk/res/android&#8221;

android:layout_width=“fill_parent”

android:layout_height=“fill_parent”

android:orientation=“vertical”>

<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=“0a2QzmzSZf-7SPfgI5CwwHFtZnf86krSsP6qbrw”/>

</

LinearLayout>

Modify main.xml:

<LinearLayoutxmlns:android=http://schemas.android.com/apk/res/android

android:id=“@+id/container”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:orientation=“horizontal”>

<fragment

android:name=“com.example.LBS.Locations”

android:id=“@+id/locationFragment”

android:layout_weight=“0.25”

android:layout_width=“20dp”

android:layout_height=“match_parent”/>

<fragment  

android:name=“com.example.LBS.ShowMap”

android:id=“@+id/mapFragment”

      android:layout_weight=“1”

android:layout_width=“0px”

android:layout_height=“match_parent”/>

</LinearLayout>

Modify MainActivity.Java:

package com.example.LBS;

import android.app.Activity;

import android.os.Bundle;

import com.google.android.maps.MapActivity;

public class LocationBasedServiceActivity extends MapActivity {

//** Called when the activity is first created. */

@Override

publicvoid onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

        setContentView(R.layout. main);

    }

@Override

protectedboolean isRouteDisplayed() {

// TODO Auto-generated method stub

returnfalse;

    }

}

At Last : AndroidManifest.xml:

<?xmlversion=“1.0”encoding=“utf-8”?>

<manifestxmlns:android=http://schemas.android.com/apk/res/android

package=“com.example.LBS”

android:versionCode=“1”

android:versionName=“1.0”>

<uses-sdkandroid:minSdkVersion=“11”/>

<uses-permission  android:name=“android.permission.INTERNET”/>

<application 

android:icon=“@drawable/ic_launcher”

android:label=“My Location”>

<uses-libraryandroid:name=“com.google.android.maps”/>

<activity 

android:label=“@string/app_name”

android:name=“.LocationBasedServiceActivity”>

<intent-filter>

<actionandroid:name=“android.intent.action.MAIN”/>

<categoryandroid:name=“android.intent.category.LAUNCHER”/>

</intent-filter>

</activity>

</application>

</manifest>

That’s it, Lets Check the Application!!…

This slideshow requires JavaScript.

Advertisements

About Anindita
Anindita Basak is working as Big Data Cloud Consultant in Microsoft. Worked in multiple MNCs as Developer & Senior Developer on Microsoft Azure, Data Platform, IoT & BI , Data Visualization, Data warehousing & ETL & of course in Hadoop platform.She played both as FTE & v- employee in Azure platform teams of Microsoft.Passionate about .NET , Java, Python & Data Science. She is also an active Big Data & Cloud Trainer & would love share her experience in IT Training Industry. She is an author, forum contributor, blogger & technical reviewer of various books on Big Data Hadoop, HDInsight, IoT & Data Science, SQL Server PDW & PowerBI.

7 Responses to Building Google Map Based Applications on Android Tablet Device with Google Map API

  1. Pingback: E-bike

  2. Pingback: LINKURI ORTODOXE

  3. Pingback: eliquid günstig kaufen

  4. Pingback: Buy Guaranteed Facebook Fans

  5. Pingback: Elektrische Zigarette kaufen

  6. Pingback: small business seo packages

  7. Pingback: Designer Tablet Sports Trendy Looks, Last Year?s Softwarehothotblogs.info – 5 | hothotblogs.info - 5

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: