Hello everyone, in this tutorial I will show you how to start with Google Maps in android.
Follow these steps while connecting to Google Maps in android.
Create a project with “Google APIs” as the Base SDK.
First, if you are testing the application on the Android emulator, locate the SDK debug certificate located in the default folder of “C:Documents and Settings
For simplicity, copy this file (debug.keystore) to a folder in C: (for example, create a folder called “C:Android”).
Using the debug keystore, you need to extract its MD5 fingerprint using the Keytool.exe application included with your JDK installation. This fingerprint is needed to apply for the free Google Maps key. You can usually find the Keytool.exe from the “C:Program FilesJava
Issue the following command.
keytool.exe -list -alias androiddebugkey -keystore “C:androiddebug.keystore” -storepass android -keypass android
If you have added the path in the environment variables then you can execute this command from anywhere on the command line.
After that you will get a key, copy that key and go to http://code.google.com/android/maps-api-signup.html
Paste your code there and get the “Google Maps API key”
Now go to the main.xml file in your project and do as follows.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <view android:id="@+id/mv" class="com.google.android.maps.MapView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:clickable="true" android:apiKey="your_api_key goes here" /> </LinearLayout>
Now you are done save this file and load this xml file as layout in the java file.
Make sure you have internet connection in the emulator otherwise the map will not load.
This is the java file
package pack.coderzheaven; import android.os.Bundle; import com.google.android.maps.MapActivity; public class MapDemo extends MapActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } @Override protected boolean isRouteDisplayed() { return false; } }
At last the Most important things to do in the AndroidManifest file
Add necessary permissions like INTERNET etc and include this library
inside the application tag.
My Manifest will look like this
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="pack.coderzheaven" android:versionCode="1" android:versionName="1.0"> <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" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".MapDemo" 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> <uses-sdk android:minSdkVersion="6" /> </manifest>
Now you are done go on and run the application
You can download the complete source code of the project here
Pingback: How to add markers on our desired location in Google Maps Android? | Coderz Heaven