【问题标题】:Google play services in google maps谷歌地图中的谷歌播放服务
【发布时间】:2015-03-27 07:08:50
【问题描述】:

当我尝试运行我的应用程序时,我遇到了这个错误: “除非您更新 google play 服务,否则此应用将无法运行”

我已经尝试了很多这里的东西,但没有。 我在 Android Studio 的帮助下生成了应用程序。 我已将第 22 版下载到 Google Play 服务,并为 Froyo 下载了第 12 版 Google Play 服务 我的项目是 Api 17,当我在手机中运行项目时,它显示正常。

清单

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

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


    <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="@string/google_maps_key" />

        <activity
            android:name=".MapsActivity"
            android:label="@string/title_activity_maps" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

主活动

package com.example.googlemaps.googlemaps;

import android.app.Dialog;
import android.location.Location;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;


import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMyLocationChangeListener;
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 MapsActivity extends FragmentActivity implements OnMyLocationChangeListener {

    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_maps);
        int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
        if(status!=ConnectionResult.SUCCESS){
            int requestCode=10;
            Dialog dialog=GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
                 dialog.show();
             }
             else{
                 SupportMapFragment fm=(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
                 mMap=fm.getMap();
                 mMap.setMyLocationEnabled(true);
                 mMap.setOnMyLocationChangeListener(this);
             }


    }

    @Override
    public void onMyLocationChange(Location location) {
        // TODO Auto-generated method stub
        // TextView tvLocation=(TextView)findViewById(R.id.textView1);
        double latitude=location.getLatitude();
        double longitude=location.getLongitude();
        LatLng latLng=new LatLng(latitude,longitude);
        mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
        mMap.animateCamera(CameraUpdateFactory.zoomTo(15));
        // tvLocation.setText("Latitude:"+latitude+", Longitude:"+longitude);
    }
}

【问题讨论】:

  • 那么问题出在哪里?您提到如果您在手机上运行该应用程序,它会显示正常。部分较旧的 api 和 android 模拟器不支持 Google play 服务,请先查看要求。看看有没有帮助。
  • 嗨,因为我也想在模拟器中显示。 API版本为17(4.4.2)
  • 试试这里写的答案:Link

标签: google-maps


【解决方案1】:

您遇到的错误是因为您没有运行 6.5 的更新版本的 Google Play 服务。确保您已将其添加到 build.gradle 文件中作为依赖项。添加以下行。

dependencies {
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.google.android.gms:play-services:6.5.87'
}

如果您的应用仅用于地图,您可以选择性地添加:

com.google.android.gms:play-services-maps:6.5.87

请参阅this 文档了解更多详情。

假设您已将清单文件中的 API_KEY 替换为您的实际 API 密钥,您应该能够看到在您的应用上运行的地图而不会出现任何错误。

更多详情请阅读Google Play Services 6.5上的官方文档。

【讨论】:

    【解决方案2】:

    对你来说是个好消息。 Google 现在为地图提供了一个独立的库,在撰写本文时,该库还处于测试阶段

    Android 版 Maps SDK 现在通过独立的静态库分发。以前,Android 版 Maps SDK 作为 Google Play 服务的一部分提供

    https://developers.google.com/maps/documentation/android-sdk/v3-client-migration

    【讨论】:

    • 对不起,我是 Android 开发的初学者,那么使用这个独立的静态库有什么好处呢?所以我不需要检查用户是否有谷歌播放服务?并在启动 mapview 时使其更快?喜欢这里的问题:stackoverflow.com/questions/26178212/…?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-18
    • 2014-05-23
    • 1970-01-01
    • 1970-01-01
    • 2017-06-06
    • 2013-07-04
    相关资源
    最近更新 更多