2015-05-19 20 views
1

我和我的朋友正在創建一個涉及谷歌地圖使用的手機應用程序,因此我們可以放置標記,一旦選定就會顯示信息。我們遇到的問題是我們無法讓Google地圖插件正常工作。無法讓谷歌地圖上班

我們完成了以下操作: - 增加了:Android支持存儲庫,Google play服務,Google存儲庫。 - 以下內容已添加到我們的gradle模塊中。

android { 
    compileSdkVersion 21 
    buildToolsVersion '21.1.2' 

    defaultConfig { 
     applicationId "com.example.wilmar.rentacube" 
     minSdkVersion 15 
     targetSdkVersion 21 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

我們還使用gradle文件同步了項目。然而,當我們嘗試在我們的模擬器中運行它時,它說我們需要更新谷歌播放服務。

任何幫助,將不勝感激, 預先感謝您:)

這是在我們的谷歌地圖活動的要求代碼:

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

import com.example.wilmar.rentacube.R; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.SupportMapFragment; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.MarkerOptions; 

public class GoogleMapsActivity extends FragmentActivity { 

    private GoogleMap mMap; // Might be null if Google Play services APK is not available. 

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

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

    /** 
    * Sets up the map if it is possible to do so (i.e., the Google Play services APK is correctly 
    * installed) and the map has not already been instantiated.. This will ensure that we only ever 
    * call {@link #setUpMap()} once when {@link #mMap} is not null. 
    * <p/> 
    * If it isn't installed {@link SupportMapFragment} (and 
    * {@link com.google.android.gms.maps.MapView MapView}) will show a prompt for the user to 
    * install/update the Google Play services APK on their device. 
    * <p/> 
    * A user can return to this FragmentActivity after following the prompt and correctly 
    * installing/updating/enabling the Google Play services. Since the FragmentActivity may not 
    * have been completely destroyed during this process (it is likely that it would only be 
    * stopped or paused), {@link #onCreate(Bundle)} may not be called again so we should call this 
    * method in {@link #onResume()} to guarantee that it will be called. 
    */ 
    private void setUpMapIfNeeded() { 
     // Do a null check to confirm that we have not already instantiated the map. 
     if (mMap == null) { 
      // Try to obtain the map from the SupportMapFragment. 
      mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)) 
        .getMap(); 
      // Check if we were successful in obtaining the map. 
      if (mMap != null) { 
       setUpMap(); 
      } 
     } 
    } 

    /** 
    * This is where we can add markers or lines, add listeners or move the camera. In this case, we 
    * just add a marker near Africa. 
    * <p/> 
    * This should only be called once and when we are sure that {@link #mMap} is not null. 
    */ 
    private void setUpMap() { 
     mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker")); 
    } 
} 

注意!:該代碼自動生成通過Android Studio!

+0

是否創建了谷歌地圖的API密鑰? –

+0

是的,這已經創造了 – Uridel

+0

發佈您的代碼,請 –

回答

0

它說,我們需要更新谷歌播放服務

那麼,谷歌地圖是谷歌的部分播放這也將在設備運行該應用程序上安裝服務。如果演示應用程序表示您需要更新Play服務,則表示Google Play服務未安裝在設備上,或者其版本低於應用程序的要求。例如。安裝在設備上的Play服務的版本爲6.5.11,應用程序需要7.0 - 在開始時您會獲得更新對話框。
只有一個解決方案。打開Goog​​le Play Market,找到Google Play服務並將其更新爲最新版本。