Google Maps Android V2 development BASICS (1)

Source: Internet
Author: User
Tags android sdk manager

I received a small task yesterday. Based on the development on Google Maps Android API V2, I didn't know that Google Maps was upgraded to V2 at first. Remember that when I used to develop V1, I had an API key which was generated on the official website. It is found that the page for generating the API key does not exist, but the developer guide of V2, which is much more powerful than the previous one and has many improvements.

Preparations for development based on V2: 1. Start Android SDK manager and select Google Play Service SDK under the extras directory to download. After the download is complete in the android SDK directory extras \ google \ google_play_services \ libproject \ google-play-services_lib this project appears. Import it to eclipse.

2: Create a project, GoogleMap, package name: COM. example. googleMap, right-click the project, select Properties-> Android, under the project build target tab, select Google APIs or android API, under the library tab add the first step of the imported google-play-services_lib. (You can also copy the google-play-services.jar directly to your project)

3: cmd open the command window and enter the specific command C: \ Users \ Administrator> keytool-list-v-keystore "C: \ Users \ Administrator \. android \ debug. keystore "-alias androiddebugkey-storepass Android-keypass Android (where Administrator is the user name and-keypass is the password, which is generally Android), we need to use the sha1 value.

4: Open the https://code.google.com/apis/console/ to register a Google account login, the First Login will automatically create an API project, select the service option on the left, find the Google Maps Android API V2 Serivce option and open. Select the API access option on the left, create new Android key, and enter the sha1 value + ";" + package name (for example, 45: B5: e4: 6f: 36: AD: 0a: 98: 94: B4: 02: 66: 2b: 12: 17: F2: 56: 26: A0: E0; COM. example. googleMap) finally create to generate android
Key.

5. Add the android key to your androidmanifest. xml file and add it in <Application> </Application>.

<meta-data    android:name="com.google.android.maps.v2.API_KEY"    android:value="your_android_key"/>

Add the following permissions to <manifest> </manifest>, where com. example. GoogleMap is the application package name.

<permission        android:name="com.example.googlemap.permission.MAPS_RECEIVE"        android:protectionLevel="signature"/><uses-permission android:name="com.example.googlemap.permission.MAPS_RECEIVE"/>

6. Add the following permissions to androidmanifest. xml.

<uses-permission android:name="android.permission.INTERNET"/><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/><uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/><!-- The following two permissions are not required to use     Google Maps Android API v2, but are recommended. --><uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/><uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

Because Google Maps V2 requires the support of OpenGL ES V2, the following elements must be added to androidmanifest. xml:

<uses-feature        android:glEsVersion="0x00020000"        android:required="true"/>

7. Add a map. Main. XML is as follows:

<?xml version="1.0" encoding="utf-8"?><fragment xmlns:android="http://schemas.android.com/apk/res/android"          android:id="@+id/map"          android:layout_width="match_parent"          android:layout_height="match_parent"          android:name="com.google.android.gms.maps.MapFragment"/>

Add the following code to mainactivity. Java:

package com.example.googlemap;import android.app.Activity;import android.os.Bundle;public class MainActivity extends Activity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);    }}

A simple V2 map is complete. Of course, Google Maps requires a lot. The real machine must be a native Rom. Google Maps and Google Play Serivce are installed and can be searched and installed on the official electronic market.

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.