Sunday, 27 July 2014

Google Maps

1. create new project as android application project and give the name of project
2. import the Google Play Services into Eclipse
a. In goto File ⇒ Import ⇒ Android ⇒ Existing Android Code Into Workspace
b. Click on Browse and select Google Play Services project from your android sdk folder.
You can locate play services library project from
android-sdk-windows\extras\google\google_play_services\libproject\google-play-services_lib
c. Importantly while importing check Copy projects into workspace option as shown in the below image.
d. dont forget to mark the checkbox for “copy projects into workspace”
3. Generate the google map api key
a. get md5 and sha code using following command on windows
keytool -list -v -keystore “%USERPROFILE%\.android\debug.keystore” -alias androiddebugkey -storepass android -keypass android
on linux or mac use following command
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
b. Goto Google API console
c. Select the services -> Google maps Android API V2 -> make the toggle button as on
d. Select API Access and Create new Android key
e. Click create new android key
f. Paste your SHA1 fingerprint here and put “;”(semicoln) and write your packagename after semicolon
g. It will create API key for ypu copy it.
4. In your project link the google play service library in your project
5. Add the Map Key in the manifest file. Open AndroidManifest.xml file and add the following code
before tag. Replace the android:value with your map key which you got from google console.
6. Add following permissions to your manifest file
1<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
2    <uses-permission android:name="android.permission.INTERNET" />
3    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
4    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
5  
6    <!-- Required to show current location -->
7    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
8    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
7. Include the map fragment in your xml file
1<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2    android:layout_width="fill_parent"
3    android:layout_height="fill_parent" >
4    <fragment
5        android:id="@+id/map"
6        android:name="com.google.android.gms.maps.MapFragment"
7        android:layout_width="match_parent"
8        android:layout_height="match_parent"/>
9</RelativeLayout>
8. call the initilizeMap() methos from oncreatemethod
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
“Sorry! unable to create maps”, Toast.LENGTH_SHORT)
.show();
}
}
}
@Override
protected void onResume() {
super.onResume();
initilizeMap();
}
9. Now run your project you can see the map
If You are Looking For Mobile App Development Company
Here is Stark for you. Stark Digital is a top-notch mobile app development company offering mobile application development services for iPhone, iPad, and Android.
Address-
Shinde Complex, Near Maratha Mandir, Shinde Nagar, Bavdhan,Pune, Maharashtra 411021.