Implement GoogleMaps in Android Studio

Allow your users to explore the world with rich maps provided by Google. Identify locations with custom markers, augment the map data with image overlays, embed one or more maps as fragments, and much more.The Google Maps Android API allows you to include maps and customized mapping information in your app.

Key Developer Features

Add maps to your app: 

With Google Maps Android API v2, you can embed maps into an activity as a fragment with a simple XML snippet. The new Maps offer exciting features such as 3D maps; indoor, satellite, terrain, and hybrid maps; vector-based tiles for efficient caching and drawing; animated transitions; and much more. Add a map object.

Customize the map: 

Add markers onto the map to indicate special points of interest for your users. You can define custom colors or icons for your map markers to match your app's look and feel. To further enhance the app, draw polylines and polygons to indicate paths or regions, or provide complete image overlays. Draw markers.

Control the user's view: 

Give your users a different view of the world with the ability to control the rotation, tilt, zoom, and pan properties of the "camera" perspective of the map. Change the view.

Add Street View to your app: 

Embed Street View into an activity and let your users explore the world through panoramic 360-degree views. Programmatically control the zoom and orientation (tilt and bearing) of the Street View camera, and animate the camera movements over a given duration. Add Street View.

GoogleMap Steps

1. In Eclipse ->Android SDK Manager-> update the ->Google play Services.

2. Import Google play Services into Workspace in Eclipse.
    a. File -> Import -> Android -> Existing Android Code into Workspace.
    b. And browse the file from Sdk/extras/google/google_play_services.
    c. Copy into Workspace.
    d. Click Finish.

3. Then after create a new android application project.

4. Add the Google play store to the created project.
    a.Right click the created project, select Properties, from left menu select JavaBuildPath, and from right side select Projects and click on Add button, from the given list select Google play Services click ok to add.

5. Add Google play store lib to created project.
    a.Right click the created project, select properties, from lest menu select Android and from right side bottom Library click on Add Button.
    b.From the given list select "Google Play Service" and click apply then click ok.

6.Open Google Console to Generate the Key. You can login to Google Console with any gmail id.

7.From left side menu select "API's".

8.From Right side select Google Maps Android API.

9.Next Click on "Enable API" to enable the API.

10.Next Select "Credentials"

11.From Right Side Select Click on "Create new Key"

12.From the Dialog Select "Android Key"

13.Then simply click on "Create" Button to generate public key.

14.It Generates Key like.

15.Copy and save the API Key for further use.

16.Return back to Eclipse create project write the Code.
a. XML Snippet in Layout
<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
<fragment
        android:name="com.google.android.gms.maps.MapFragment"
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

b.What is Fragment?

A Fragment represents a behavior or a portion of user interface in an Activity. You can combine multiple fragments in a single activity to build a multi-pane UI and reuse a fragment in multiple activities.

17. Permissions in AndroidManifestfile.xml.
<permission
        android:name="user defined package.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />
<uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
<uses-permission android:name="user defined package.permission.MAPS_RECEIVE"  />
< uses-permission android:name="android.permission.INTERNET" />

eSd card permission:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Permission to access Google services:

<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

wifi permission:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

GPS permission:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

18. Add Metadata to Manifest file a.
<meta-data android:name="com.google.android.maps.v2.API_KEY"
           android:value="AIzaSyA753rejZC2Mv9SdDA4-yNS3k1YTqrV3do"/>

b. In meta android:value is the generated key in Google console.

19. Run in Real Device for better result.
Comment via Facebook
0 Comment via Google

0 تعليقات:

Post a Comment