"Go" Android domestic integration using Google Maps

Source: Internet
Author: User

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-data android:name= "com.google.android.gms.version" android:value= "@integer/google_play_services_version"/> <meta-data android: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 "><textview android:text= "@string/hello_world" android:layout_width=  "wrap_content" android:layout_height=  "wrap_content"/> <fragment android:id= "@+id/map" android: Layout_width= "match_parent" android:layout_height= "match_parent" android:name= " Com.google.android.gms.maps.MapFragment "/></ Relativelayout>              

Mainactivity

Package Map.randy.com.googlemapdemo;Import Android.os.Bundle;Import android.support.v4.app.FragmentActivity;Import Com.google.android.gms.maps.CameraUpdateFactory;Import Com.google.android.gms.maps.GoogleMap;Import com.google.android.gms.maps.MapFragment;Import Com.google.android.gms.maps.OnMapReadyCallback;Import Com.google.android.gms.maps.model.LatLng;Import com.google.android.gms.maps.model.MarkerOptions;PublicClassMainactivityExtendsFragmentactivityImplementsOnmapreadycallback {@OverrideProtectedvoidOnCreate (Bundle savedinstancestate) {Super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Mapfragment mapfragment = (mapfragment) Getfragmentmanager (). Findfragmentbyid (R.id.map); Mapfragment.getmapasync (This ); } @Override public void Onmapready (googlemap googlemap) {latlng Sydney = new Latlng (-33.867,  151.206); Googlemap.setmylocationenabled (true); Googlemap.movecamera (Cameraupdatefactory.newlatlngzoom (Sydney, 13) ); Googlemap.addmarker (new Markeroptions (). Title ("Sydney"). Snippet ("The most populous city inAustralia.") . Position (Sydney)); }}

Run:

But this is in FQ case, if there is no FQ, can only be blank ...

And Google provides a mask layer in V2 that developers can use to customize the map.

    Package Map.randy.com.googlemapdemo;Import Android.os.Bundle;Import android.support.v4.app.FragmentActivity;Import Com.google.android.gms.maps.CameraUpdateFactory;Import Com.google.android.gms.maps.GoogleMap;Import com.google.android.gms.maps.MapFragment;Import Com.google.android.gms.maps.OnMapReadyCallback;Import Com.google.android.gms.maps.model.LatLng;Import com.google.android.gms.maps.model.MarkerOptions;Import com.google.android.gms.maps.model.TileOverlayOptions;Import Com.google.android.gms.maps.model.TileProvider;Import Com.google.android.gms.maps.model.UrlTileProvider;Import java.net.MalformedURLException;Import Java.net.URL;Import Java.util.Random;PublicClassMainactivityExtendsFragmentactivityImplementsOnmapreadycallback {@OverrideProtectedvoidOnCreate (Bundle savedinstancestate) {Super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Mapfragment mapfragment = (mapfragment) Getfragmentmanager (). Findfragmentbyid (R.id.map); Tileprovider Tileprovider =New Urltileprovider (512,512) {@OverridePublic URLGettileurl (int x,int y,int zoom) {/* Define The URL pattern for the tile images */random random =New Random (); String s = String.Format ("HTTP://MT" +random.nextint (3) +". Google.cn/vt/[email Protected]&hl=zh-cn&gl=cn&x=%d&y=%d&z=%d&s=galil", X, Y,zoom);if (!checktileexists (x, y, zoom)) {ReturnNull }try {ReturnNew URL (s); }catch (Malformedurlexception e) {ThrowNew Assertionerror (e); } } }; tileoverlayoptions TPO =New Tileoverlayoptions (); Tpo.tileprovider (Tileprovider); Mapfragment.getmap (). Addtileoverlay (TPO); Mapfragment.getmap (). Setmaptype (Googlemap.map_type_none); Mapfragment.getmapasync (this); }PrivateBooleanChecktileexists (int x,int y,int zoom) {int minzoom =12;int maxzoom =16;if ((Zoom < Minzoom | | zoom > Maxzoom)) {return FALSE; } return true;}  @Override public void onmapready (GoogleMap googlemap) {latlng Sydney = new LatLng (-33.867, 151.206); googlemap.setmylocationenabled (true); Googlemap.movecamera ( Cameraupdatefactory.newlatlngzoom (Sydney, 13)); Googlemap.addmarker (new markeroptions (). Title ( "Sydney"). Snippet ( "the most populous city in Australia."). Position (Sydney)); }} 

However, the test found that the quality of the image achieved by this method is somewhat low. I'm so embarrassed ...

Cond...

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"Go" Android domestic integration using Google Maps

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.