【问题标题】:Can't get google maps to work无法让谷歌地图工作
【发布时间】:2015-05-19 11:39:57
【问题描述】:

我和我的朋友正在创建一个涉及使用谷歌地图的手机应用程序,这样我们就可以放置标记,一旦选择就会显示信息。我们遇到的问题是我们无法让谷歌地图插件工作。

我们做了以下工作: - 新增: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 文件同步。但是,当我们尝试在模拟器中运行它时,它说我们需要更新 google play 服务。

任何帮助将不胜感激, 提前谢谢你。:)

我们的谷歌地图活动中的代码应要求:

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 自动生成!

【问题讨论】:

标签: android google-maps android-studio google-play-services


【解决方案1】:

它说我们需要更新谷歌播放服务

好吧,Google 地图是 Google Play 服务的一部分,应该安装在您的设备上以运行此应用程序。如果演示应用提示您需要更新 Play 服务,则意味着设备上未安装 Google Play 服务或它们的版本低于应用所需的版本。例如。设备上安装的 Play 服务版本为 6.5.11,应用程序需要 7.0 - 您会在开始时看到更新对话框。
只有一种解决方案。打开 Google Play 市场,找到 Google Play 服务并将其更新到最新版本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-19
    • 2016-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-02
    • 2011-03-25
    • 2016-12-22
    相关资源
    最近更新 更多