2013-04-04 160 views
2

我在實現Google Maps片段時遇到了嚴重問題到我的Android應用程序。基本上, 我遵循了Google網站上的所有說明。在獲得Google Maps API v2密鑰,設置佈局和清單,導入google-play-service庫並使用谷歌示例代碼啓動GoogleMap之後,我發現模擬器不支持Google Maps API v2,所以我上線並下載最新版本的com.android.vending.apk和com.google.android.gms.apk,然後使用adb install將它們安裝到我的模擬器中(與此處的情況相同:This app won't run unless you update Google Play Services (via Bazaar))。安裝完成後,我終於可以實現MapFragment的界面。Google地圖中的錯誤,「無法找到com.google.android.gsf.gservices的提供者信息」和「無法找到com.google.settings的提供者信息」

但是當我在Android模擬器(OS 4.1.2; API 16)中運行它時,地圖上沒有任何工作。 「無法找到com.google.android.gsf.gservices的提供者信息」錯誤不斷出現。我不確定它是否與無線提供商有關。有誰知道爲什麼它一直出來?任何建議將不勝感激!

解釋一些早期的問題:地圖顯示正確。但地圖上的按鈕(「+」和「 - 」)完全不起作用。我也不能點擊或拖動地圖。每當我點擊任何按鈕,拖動或雙擊地圖,它都沒有給我任何迴應,但LogCat中的錯誤消息顯示「無法找到com.google.android.gsf.gservices的提供者信息」。

這是我在AndroidManifest.xml代碼:

 <?xml version="1.0" encoding="utf-8"?> 
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="com.example.trackmyexercise" 
     android:versionCode="1" 
     android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="12" 
     android:targetSdkVersion="17" /> 

    <permission 
     android:name="com.example.trackmyexercise.permission.MAPS_RECEIVE" 
     android:protectionLevel="signature" /> 

    <uses-permission android:name="com.example.trackmyexercise.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" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="com.example.trackmyexercise.MainActivity" 
      android:label="@string/app_name" > 
      <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="AIzaSyANkR-VPI4zy5IpYGK2Z0T1omLq3C46rFE" /> 
    </application> 

</manifest> 

這裏是我的佈局代碼:

<?xml version="1.0" encoding="utf-8"?> 
<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" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".MainActivity" > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/hello_world" /> 

    <fragment 
     android:id="@+id/map" 
     android:name="com.google.android.gms.maps.MapFragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/recordsButton" 
     android:layout_alignParentTop="true" /> 

</RelativeLayout> 

這裏是我的MainActivity代碼:

package com.example.trackmyexercise; 

import android.os.Bundle; 
import android.app.Activity; 
import android.app.FragmentTransaction; 
import android.view.Menu; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.MapFragment; 

public class MainActivity extends Activity { 
    GoogleMap myMap; 
    MapFragment myMapFragment; 

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

     myMapFragment = MapFragment.newInstance(); 
     FragmentTransaction fragmentTransaction = getFragmentManager() 
       .beginTransaction(); 
     fragmentTransaction.add(R.id.map, myMapFragment); 
     fragmentTransaction.commit(); 

     myMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)) 
       .getMap(); 
     this.setUpMapIfNeeded(); 
     myMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 

    private void setUpMapIfNeeded() { 
     if (myMap == null) { 
      myMap = ((MapFragment) getFragmentManager().findFragmentById(
        R.id.map)).getMap(); 
     if (myMap != null) { 
     } 
    } 
    } 
} 
+0

所以問題是,按鈕不起作用?地圖顯示是否正確? – 2013-04-04 22:41:50

+0

尼斯詳細的問題,但我們不知道什麼是不工作 – 2013-04-04 22:49:12

+0

地圖本身不工作。基本上它只是一張圖片,它上面的按鈕都不起作用。 – 2013-04-05 17:56:27

回答

4

錯誤就出在這裏 - >android:name="com.example.tackmyexercise.permission.MAPS_RECEIVE"

我想這是你的軟件包名稱不正確。

應該"com.example.trackmyexercise.permission.MAPS_RECEIVE"

+0

謝謝你的評論。我沒有注意到這個拼寫錯誤。 – 2013-04-05 19:03:29

+1

但即使我將其更改爲正確的一個,同樣的錯誤仍然不斷彈出。 – 2013-04-05 19:10:42

+0

這真的很奇怪。嘗試卸載和resinstalling。 – androidlab 2013-04-06 10:07:02

0

我遵循同樣的教程,有同樣的問題,因爲你,並設法通過執行以下操作來獲得一個工作地圖:

  • 右鍵單擊項目
  • 選擇'項目屬性'
  • 在左側菜單中選擇'Android'
  • 在'項目構建目標'下確保選擇了'Android XX'(我使用4.2。 2),而不是谷歌的API
  • 另外,請確保您的Android虛擬設備具有「安卓x.x中」作爲目標版本,而不是谷歌的API

爲我工作,希望它可以幫助你!

相關問題