我正在尝试开发基于google place API的应用程序。当我尝试使用时
Place place=PlacePicker.getPlace(data,this);
要么
GooglePlayServicesUtil.getErrorDialog(e.getConnectionStatusCode(), MainActivity.this, 0);
有一个错误显示不推荐使用getPlace()。我已经尝试过了
getPlace(Context, Intent)
但它没有用。请建议一个解决方案。提前致谢!
如official android documentation所述的方法
PlacePicker.getPlace(Intent, Context)
已弃用。要获得你应该使用的地方:
Place place = PlacePicker.getPlace(Context, Intent);
这就是说,错误仍然存在,你应该做的第一件事就是检查你是否使用了最新的依赖项(目前这些是10.0.1)。我建议检查你的build.gradle
文件。它应该看起来像这样:
[...]
dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:design:25.0.1'
compile 'com.android.support:support-v4:25.0.1'
compile 'com.google.android.gms:play-services-maps:10.0.1'
compile 'com.google.android.gms:play-services-location:10.0.1'
compile 'com.google.android.gms:play-services-gcm:10.0.1'
compile 'com.google.android.gms:play-services-places:10.0.1'
}
apply plugin: 'com.google.gms.google-services'
现在,这里真正重要的位是dependencies
块内的最后4行,它们是:
compile 'com.google.android.gms:play-services-maps:10.0.1'
compile 'com.google.android.gms:play-services-location:10.0.1'
compile 'com.google.android.gms:play-services-gcm:10.0.1'
compile 'com.google.android.gms:play-services-places:10.0.1'
最后一行,它必须是文档的最后一行:
apply plugin: 'com.google.gms.google-services'