Google 在 google 地图中播放服务
Google play services in google maps
我在尝试 运行 我的应用程序时遇到了这个错误:
"this app won't run unless you update google play services"
我已经尝试了这里的很多东西,但没有。
我在 Android Studio 的帮助下生成了应用程序。
我已经将 rev 22 下载到 Google Play Services 和 rev 12 of Google Play services for Froyo
我的项目是 Api 17,当我 运行 项目在 phone 时,它显示正常。
清单
<?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);
}
}
您遇到的错误是因为您不是 运行 Google Play Services 的更新版本 6.5。确保您已将其作为依赖项添加到 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 的官方文档。
对你来说是个好消息。 Google 现在为地图提供了一个独立的库,在撰写本文时 post,它处于测试阶段
The Maps SDK for Android is now distributed via a standalone static library. Previously, the Maps SDK for Android was made available as part of Google Play services
https://developers.google.com/maps/documentation/android-sdk/v3-client-migration
我在尝试 运行 我的应用程序时遇到了这个错误: "this app won't run unless you update google play services"
我已经尝试了这里的很多东西,但没有。 我在 Android Studio 的帮助下生成了应用程序。 我已经将 rev 22 下载到 Google Play Services 和 rev 12 of Google Play services for Froyo 我的项目是 Api 17,当我 运行 项目在 phone 时,它显示正常。
清单
<?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);
}
}
您遇到的错误是因为您不是 运行 Google Play Services 的更新版本 6.5。确保您已将其作为依赖项添加到 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 的官方文档。
对你来说是个好消息。 Google 现在为地图提供了一个独立的库,在撰写本文时 post,它处于测试阶段
The Maps SDK for Android is now distributed via a standalone static library. Previously, the Maps SDK for Android was made available as part of Google Play services
https://developers.google.com/maps/documentation/android-sdk/v3-client-migration