Google Map API v2 (1)

Source: Internet
Author: User
Tags android sdk manager

Official documents: https://developers.google.com/maps/documentation/android/start? Hl = zh-CN

Google before Baidu. Using google APIS is basically done on the official website. If you encounter various problems during the development process, you can find a solution by looking at the official document carefully. This article mainly aims to review and summarize it.

Google Map API v2 has changed a lot compared with v1. Do not take the v1 strategy for v2.

 

Step 1:

Open Android SDK Manager, drag to the bottom to find the Extras folder, expand, find Google Play services, and install.

Google Play services will be installed under android SDK path. My directory is ~ /Develop/android-sdk-linux/extras/google/google_play_services/

I used API 15 (4.0.3) to expand it to the corresponding directory and install Google APIs.

File> Import, select Android> Existing Android Code into Workspace, and find

~ /Develop/android-sdk-linux/extras/google/google_play_services/libprojects/google-play-services_lib /.

After the import, you can see the google-play-services_lib project in eclipse, if eclipse has set build automatically, it will automatically compile, to ensure that there is a com. google. android. otherwise, an error will be reported in the subsequent steps.

Find your project in the Package Expolorer window on the left, right-click, select Properties, select Android in the left navigation bar, find Library in the sub-window on the right, click Add, and open the project selection window, select google-play-services_lib, click OK.

After joining

Click OK.

Return to the work zone. The package directory shows two more dependence packages.

Install the googleservice package (com.google.android.gms.apk) and Google Play Store(com.android.vending.apk) on your mobile phone ).

I did not install the google service framework. play store is actually useless, but it does not affect the use of Google Map.

If you use a simulator, you can select Google APIs of the corresponding API level for target when creating AVD.

The preparation is complete.

 

Step 2 apply for KEY

To use google, you must apply for a KEY, which is bound to the APK package name and the certificate used to pack the apk.

Eclipse-> Help-> Install New Software, click Add, Name fill Keytool, Loction fill in the http://www.keytool.sourceforge.net/update, Install and restart eclipse, Keytool menu is added on the menu bar.

In the debugging phase, the default debug certificate is used for the apk packaged through eclipse run and debug. The certificate is located in the. android directory of the home directory.

Eclipse-> Keytool-> Open keystore. Enter/home/username/. android/debug. keystore in the file path. The password is the default password for the debug certificate. android

After opening, the keytool window appears at the bottom of the window, listing the selected keystore, expanding, double-click to open androiddebugkey, and find SHA1 Fingerprint and copy it.

You can also view the key through the command line, keytool Command Line Operation Reference http://docs.oracle.com/javase/6/docs/technotes/tools/windows/keytool.html

Use a gmail account to log on to the https://code.google.com/apis/console? Noredirect: Create a project and select Services in the left-side Navigation Pane. loading for the first time may be slow.

After loading, all services provided by google will appear in the right window. Find Google Maps Android API v2, set the trigger to ON, and select accept for various protocols.

Select API Access in the Navigation Pane. Click the Create Android Key button. In the pop-up window, enter "SHA1; package name". create is successful. The Key for Android apps is displayed in the API Access window, copy a string of characters in the API key column.

 

Step 3. You can start codding.

Return to eclipse, open AndroidManifest. xml, and set MAP access permission in the <manifest> root node.

 

Com. xxx. xxx is the package name. Note that these two statements must be added out of <application> </application>.

Other required licenses

 
 

Declare that OpenGL ES is used to allow the apk to be skipped when the machine that does not support OpenGL accesses the play store. Debugging is not affected if you do not write this item.

Add two metadata items to the <application> </application> node:

         

Res/values/config. xml

Api key copied in the previous step

The value of GOOGLE_MAP_API_KEY is the key applied for in step 2.3.

 

Layout/map. xml

                                                                                      

Focus on 7 ~ Line 11. The v2 map is displayed using Fragment.

13 ~ Line 31 is two textviews for debugging. It displays the latitude and longitude of the tag and the latitude and longitude of the current position.

 

MapsActivity. java

First give a simplified version

  MapsActivity  

OK, run it.

This article ends. Additional code is required for getting the mark and address in the next advanced article.

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.