advertisement
Login | Register   
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Partners & Affiliates
advertisement
advertisement
advertisement
advertisement
Average Rating: 3.8/5 | Rate this item | 73 users have rated this item.
 

Using Google Maps in Android

In a continuing exploration of Android, this article will show you how to incorporate Google Maps in your Android application.  


advertisement
n this previous article, you learned about the Eclipse development IDE and how to create a simple Android application and debug it on the Android emulator. Continuing with our exploration of Android, this article will show you how to incorporate Google Maps in your Android application.

In Android, Google Maps is now a first-class citizen. Your applications can easily integrate mapping functions. For this article, you will learn:

  • How to display Google Maps in your application
  • How to animate to a particular location
  • How to display different views for Google Maps
  • How to zoom in and out of Google Maps
Creating the Android Project
First, fire up Eclipse and create a new Android project. Call it GoogleMaps.

To display a Google Maps application in your Android application, you need to configure the required permission in your application. The permissions required are:

  • android.permission.ACCESS_COARSE_LOCATION or android.permission.ACCESS_FINE_LOCATION
  • android.permission.INTERNET
To configure your application with these permissions, you need to modify the AndroidManifest.xml file. Double-clicking on this file will display it as shown in Figure 1.


Figure 1. Configuring the File: Editing the AndroidManifest.xml file.
 
Figure 2. Adding Permissions: Click on the Permission tab, select the Uses Permission item, and click OK.

There are two ways to modify the AndroidManifest.xml file: use the tools available in the editor, or manually edit the XML file by clicking on the AndroidManifest.xml tab located at the bottom of Figure 1. If you are not familiar with the layout of the XML file, I suggest you use the editor tools available (which I am going to show shortly). If you are a seasoned Android developer, editing the XML directly is much faster.

Figure 3. Selecting Permissions: Select the various permissions you need from a drop-down list.

To add a permission to the AndroidManifest.xml file, click on the Permission tab, select the Uses Permission item, and click OK (see Figure 2).

You will now be able to select the various permissions you need from a drop-down list (see Figure 3).

Once a permission is selected, press Ctrl-S to save the AndroidManifest.xml file. Ensure that you add the permission for ACCESS_COARSE_LOCATION (or ACCESS_FINE_LOCATION) and INTERNET.

If you examine the XML file now, you will notice the two new elements added: <uses-permission> (see Listing 1).

Observe that the location of the <uses-permission>l element is within the <manifest> element and outside the <application> element. To use the Google Maps in your application, you need to add one more element to your AndroidManifest.xml file. Add the <uses-library> element as shown in Listing 2.

  Next Page: Modifying the UI
Page 1: IntroductionPage 3: Animating to a Specific Location
Page 2: Modifying the UI 
Please rate this item (5=best)
 1  2  3  4  5
advertisement