谷歌映射v2 API集成问题

时间:2014-09-29 21:17:29

标签: java android google-maps-api-2

我正在尝试将谷歌地图集成到我的Android应用程序中,但是在创建了apk并在手机上启动它(Android 4.4.4)后它崩溃了。如果我在模拟器上启动,我会收到消息“Failure [INSTALL_FAILED_MISSING_SHARED_LIBRARY]”。我能做什么不正确?

这是我的文件

MainActivity.java

private GoogleMap mMap;

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

    SupportMapFragment mapFragment =
            (SupportMapFragment)     getSupportFragmentManager().findFragmentById(R.id.map);

    if (savedInstanceState == null) {
        // First incarnation of this activity.
        mapFragment.setRetainInstance(true);
    } else {

        mMap = mapFragment.getMap();
    }
    setUpMapIfNeeded();
}

@Override
protected void onResume() {
    super.onResume();
    setUpMapIfNeeded();
}

private void setUpMapIfNeeded() {
    if (mMap == null) {
        mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                .getMap();
        if (mMap != null) {
            // Enabling MyLocation Layer of Google Map
            mMap.setMyLocationEnabled(true);
        }
    }
}

这是我的布局

<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"
            tools:context=".MainActivity" >


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

</RelativeLayout> 

清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="there is my package" >

<application

    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

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

    <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="there is my key, which i got from API console"/>


    <uses-library android:name="com.google.android.maps" />

    <permission
            android:name="(there is my app path).permission.MAPS_RECEIVE"
            android:protectionLevel="signature"/>
    <uses-permission android:name="(there is my app path).permission.MAPS_RECEIVE"/>

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

    <activity
        android:screenOrientation="portrait"
        android:name=".login.LoginActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:screenOrientation="portrait"
        android:name=".main.MainActivity"
        android:label="@string/thereismytitle" >
    </activity>
</application>

</manifest>

1 个答案:

答案 0 :(得分:0)

您的模拟器目标是否已使用Google API(Google Inc.)设置?上次我使用谷歌地图API,我有相同的经验,并且在我将目标设置为谷歌API(谷歌公司) - API级别(版本)后,它有效。