简体   繁体   中英

How to use google maps API V2 on Android

I did the following operation: -Download Google play service for Android SDK

-Import google-play-services_lib from SDK folder

-Add this like lib on my app

-Take my SHA1 code form ecplipse windows/preferences/android/build

-Create new project on Google APIs Console;

-Take my API code with: SHA1 code and project's pakage name

-Add permission on manifest:

        <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" />
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

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

and

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

on application tag -create new xml file with this code:

         <RelativeLayout xmlns: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" >

        <fragment
            android:id="@+id/map"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            class="com.google.android.gms.maps.SupportMapFragment"/>
    </RelativeLayout>

and new activity with this(it's not in main activity):

    import android.os.Bundle;
    import android.support.v4.app.FragmentActivity;

    public class Map extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map);

    }

    }

Where is the problem?

First of all I would ask what is the problem you have?:) we are not telepats.. From what I can see here, I would say you are missing another 'meta' attribute for the play services, but this would be reported into logcat:

<meta-data android:name="com.google.android.gms.version"
       android:value="@integer/google_play_services_version" />

So whats the actual problem? Is it crashing, just blank map, whats the logcat output?

Also some people try to add play services .jar file instead of referencing the project. This leads to crash as well

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM