Add Google Maps to Android app

2019-05-26 05:42发布

I need help adding Google Maps to my Android app. I have followed the instructions on https://developers.google.com/maps/documentation/android/start, but I still get an error when running the app.

This my manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.image.app" android:versionCode="1" android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".map" android:label="@string/app_name"
        android:configChanges="keyboardHidden|orientation">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <meta-data android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyBHPmNLCVvmVSCNTWYvhMUB65f1dwqSG5Y" />
</application>
<permission android:name="com.image.app.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.image.app.permission.MAPS_RECEIVE" />
<!-- Access Internet -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission
    android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- Take picture -->
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- GET Latitude Longitude -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:glEsVersion="0x00020000"
    android:required="true" />

This is my main class:

import android.app.Activity;
import android.os.Bundle;

 public class map extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map);
}
 }

This is my xml:

<?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" />

1条回答
兄弟一词,经得起流年.
2楼-- · 2019-05-26 06:01

Go to windows. Android sdk manager. Scroll down choose google play services under extras and install

enter image description here

Copy the google-play services_lib library project to your workspace. The library project can be found under the following path.

     <android-sdk-folder>/extras/google/google_play_services/libproject/google-play-services_lib library project .

Click File > Import, select Android > Existing Android Code into Workspace, and browse the workspace import the library project.

To check if its a library project. Right click got properties choose android. You see Is Library checked as below.

enter image description here

Next refer the library project in your android map project.

Right click on your android map project goto properties. choose android. click add browse the library project and click add and apply.

enter image description here

Make sure your api is 12 and above. If not you should use support fragment which requires support library.

查看更多
登录 后发表回答