java - LocationRequest 构造函数被标记为内部

标签 java android location

我正在尝试使用 com.google.android.gms:play-services-location:12.0.0 在我的 Android 应用中设置位置更新,但出现以下错误:

LocationRequest constructor is marked as internal and should not be accessed from apps

我的位置更新请求如下所示:

locationClient.requestLocationUpdates(
    new LocationRequest()
        .setInterval(5000)
        .setFastestInterval(1000)
        .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY),
    locationCallback,
    null
);

我关注了docsexample , 这样做的方式相同。如果我不应该调用 new LocationRequest(),那么正确的方法是什么?

最佳答案

使用静态方法LocationRequest create().

 LocationRequest locationRequest = LocationRequest.create();
 locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
 locationRequest.setInterval(5000);
 locationRequest.setFastestInterval(1000);

关于java - LocationRequest 构造函数被标记为内部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49488903/

相关文章:

java - Chrome 自定义标签在浏览时预加载网页?

android - Location getAccuracy() 这个函数有什么作用?

ios - 多次触发 MapBox regionDidChangeAnimated

java - 将图像制作为 "boundary"

java - 如何创建扩展 AuditingEntityListener 的自定义审核实体监听器

android - 无法在 Android Studio 中调试 React Native

java - GoogleMap V2 不从用户当前位置开始

java - 如何从接口(interface)类型的实现中获取该接口(interface)未提供的特定方法?

java - 是否可以将文件中的所有字节存储到字节数组中?

java - 进度条中形状的填充