Android Home Integration using Google Maps

Source: Internet
Author: User

extends:http://blog.csdn.net/qduningning/article/details/44778751

Due to the public to do well-known reasons in the domestic use of Google Maps is not very convenient, in the development if the direct use will have some problems. But the domestic such as Baidu Map, gold map, etc. can not provide detailed map data abroad, so study it,,,

Using Google Maps Android API v2
使用谷歌提供的SDK,Android Studio开发。
    1. First, ensure that the Google Play service is installed in the SDK manager.

2. Create a new project Googlemapdemo, then file->project structure->[app]->->dependences, click the plus sign to add the play service dependency.

3. To use Google Low, you need to apply for a key to Google developers console.
First create a project, and then in the API tab to select the Google Maps Android API v2, you can also choose a few, such as JS backup.

Add an Android keyin the Credentials label public API access.

Generate a SHA-1 fingerprint using the KeyStore used for signing, you can use Debug.kestore first. Mine is under the C:\Users\RANDY.android\.
keytool -list -v -keystore debug.keystore
Password: Android
Fill in the specified input box with the generated fingerprint, create OK. An API KEY is generated at the same time.

4. manifest file for the configuration project:

<?XML version= "1.0" encoding= "Utf-8"?><Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Map.randy.com.googlemapdemo" >    <uses-permissionAndroid:name= "Android.permission.INTERNET"/>    <uses-permissionAndroid:name= "Android.permission.ACCESS_NETWORK_STATE"/>    <uses-permissionAndroid:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>    <!--The following permissions is not required to use Google Maps for Android API v2, but is recommended. -    <uses-permissionAndroid:name= "Android.permission.ACCESS_COARSE_LOCATION"/>    <uses-permissionAndroid:name= "Android.permission.ACCESS_FINE_LOCATION"/>    <uses-featureandroid:glesversion= "0x00020000"android:required= "true"/>    <ApplicationAndroid:allowbackup= "true"Android:icon= "@mipmap/ic_launcher"Android:label= "@string/app_name"Android:theme= "@style/apptheme" >        <ActivityAndroid:name=". Mainactivity "Android:label= "@string/app_name" >            <Intent-filter>                <ActionAndroid:name= "Android.intent.action.MAIN" />                <categoryAndroid:name= "Android.intent.category.LAUNCHER" />            </Intent-filter>        </Activity>        <Meta-dataAndroid:name= "Com.google.android.gms.version"Android:value= "@integer/google_play_services_version" />        <Meta-dataAndroid:name= "Com.google.android.maps.v2.API_KEY"Android:value= "*api_key*"/>    </Application></Manifest> 

5. Configure activity and use fragment to display the map.
Layout

:<Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Tools:context=". Mainactivity ">    <TextViewAndroid:text= "@string/hello_world"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content" />    <FragmentAndroid:id= "@+id/map"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:name= "Com.google.android.gms.maps.MapFragment"/></Relativelayout>

ImportAndroid.os.Bundle;Importandroid.support.v4.app.FragmentActivity;Importcom.google.android.gms.maps.CameraUpdateFactory;ImportCom.google.android.gms.maps.GoogleMap;Importcom.google.android.gms.maps.MapFragment;ImportCom.google.android.gms.maps.OnMapReadyCallback;ImportCom.google.android.gms.maps.model.LatLng;Importcom.google.android.gms.maps.model.MarkerOptions; Public classMainactivityextendsFragmentactivityImplementsOnmapreadycallback {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); Mapfragment mapfragment=(mapfragment) Getfragmentmanager (). Findfragmentbyid (R.id.map); Mapfragment.getmapasync ( This); } @Override Public voidOnmapready (GoogleMap googlemap) {latlng Sydney=NewLATLNG (-33.867, 151.206); Googlemap.setmylocationenabled (true); Googlemap.movecamera (Cameraupdatefactory.newlatlngzoom (Sydney,13)); Googlemap.addmarker (Newmarkeroptions (). Title ("Sydney"). Snippet ("The most populous city in Australia."). Position (Sydney)); }} 

Android Home Integration using Google Maps

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.