现在的位置: 首页 > 综合 > 正文

Showing current location in Google Maps using API V2 with SupportMapFragment

2013年08月23日 ⁄ 综合 ⁄ 共 3372字 ⁄ 字号 评论关闭

Showing current location in Google Maps using API V2 with SupportMapFragment

January 6, 2013

By 

In this article, we will create an Android application which will display current location in Google Maps using Google Maps Android API V2.

Since the Google Map is displayed using SupportMapFragment, this application can run in Android API Level 8 or above.

In order to use MapFragment for Google Maps, we need Android device with API level 12 or above.

This application is developed in Eclipse 4.2.1 with ADT plugin ( 21.0.0 ) and Android SDK ( 21.0.0 ). This application is tested in a real Android Phone with Android ( 2.3.6 ).

An alternative method for this application is available at Showing
current location using OnMyLocationChangeListener in Google Map Android API V2


1. Download and configure Google Play Services Library in Eclipse

Google Map for Android is now integrated with Google Play Services. So we need to set up Google Play Service Library for developing Google Map application in Android.

Please follow the given below link to setup Google Play Service library in Eclipse.

http://developer.android.com/google/play-services/setup.html


2. Create a new Android Application Project namely “LocationInGoogleMapV2″

Create a new Android Application Project

Figure 1 : Create a new Android Application Project


3. Configure Android Application Project

Configure Project

Figure 2 : Configure Project


4. Design Application Launcher Icon

Designing Application Launcher Icon

Figure 3 : Designing Application Launcher Icon


5. Create a blank activity

Create a blank activity

Figure 4 : Create a blank activity


6. Enter Main Activity Details

Enter Main Activity Details

Figure 5 : Enter Main Activity Details


7. Link to Google Play Service Library

Link Google Play Services Library to this project

Figure 6 : Link Google Play Services Library to this project


8. Get the API key for Google Maps Android API v2 

We need to get an API key from Google to use Google Maps in Android application. Please follow the given below link to get the API key for Google Maps Android API v2.

https://developers.google.com/maps/documentation/android/start


9. Add Android Support library to this project

By default, Android support library (android-support-v4.jar ) is added to this project by Eclipse IDE to the directory libs. If it is not added, we can do it manually by doing the following steps :

  • Open Project Explorer by Clicking “Window -> Show View -> Project Explorer”
  • Right click this project
  • Then from popup window, Click “Android Tools -> Add Support Library “

10. Update the file AndroidManfiest.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?xml

version
="1.0"

encoding
="utf-8"?>
<manifest

抱歉!评论已关闭.