Add Google Maps to Android app

半腔热情 提交于 2019-12-12 10:12:58

问题


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:


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

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.

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.

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



来源:https://stackoverflow.com/questions/16395495/add-google-maps-to-android-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!