【问题标题】:PlacePicker.getPlace() and GooglePlayServicesUtil.getErrorDialog() is deprecatedPlacePicker.getPlace() 和 GooglePlayServicesUtil.getErrorDialog() 已弃用
【发布时间】:2017-04-01 11:02:10
【问题描述】:

我正在尝试开发基于 google place API 的应用程序。当我尝试使用时

 Place place=PlacePicker.getPlace(data,this);

或

   GooglePlayServicesUtil.getErrorDialog(e.getConnectionStatusCode(), MainActivity.this, 0);

显示不推荐使用 getPlace() 时出现错误。我已经尝试过

 getPlace(Context, Intent)

但它不起作用。请提出解决方案。提前致谢!

【问题讨论】:

  • 您在使用新的 GoggleApiClient 吗?
  • 是的,我正在使用新的 GoogleApiClient
  • 您是否在 gradle 依赖项中添加了 compile 'com.google.android.gms:play-services-places:9.6.1' 的内容?
  • “没有工作”是一个非常模糊的描述,请更详细,究竟是什么不起作用..
  • 是的,我添加了compile 'com.google.android.gms:play-services-places:9.6.1'

标签: android google-maps-api-3 google-places-api google-places


【解决方案1】:

如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'

最后一行,它HAS是文档的最后一行:

apply plugin: 'com.google.gms.google-services'

【讨论】:

    猜你喜欢
    • 2016-08-30
    • 2012-03-01
    • 2014-02-12
    • 1970-01-01
    • 2012-12-05
    • 2023-02-19
    • 1970-01-01
    • 2015-06-28
    • 1970-01-01
    相关资源
    最近更新 更多