LocationRequest 构造函数被标记为内部
LocationRequest constructor is marked as internal
我正在尝试使用 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
);
我遵循了 docs and the example,它们的做法相同。如果我不应该调用 new LocationRequest()
,那么正确的方法是什么?
使用静态方法LocationRequest create ()
.
LocationRequest locationRequest = LocationRequest.create();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(5000);
locationRequest.setFastestInterval(1000);
LocationRequest 初始化程序已更改为最新的 Google 播放服务依赖项(> 12.0.0)。现在你可以使用它的 create() 方法来初始化它。例如
LocationRequest request = LocationRequest.create();
在科特林中:
private val locationRequestSettings = LocationRequest.create().apply {
fastestInterval = 1000
interval = 1000
priority = LocationRequest.PRIORITY_HIGH_ACCURACY
smallestDisplacement = 1.0f
}
然后像这样使用:
fusedLocationProviderClient.requestLocationUpdates(
locationRequestSettings,
YourLocationCallback,
null
)
我正在尝试使用 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
);
我遵循了 docs and the example,它们的做法相同。如果我不应该调用 new LocationRequest()
,那么正确的方法是什么?
使用静态方法LocationRequest create ()
.
LocationRequest locationRequest = LocationRequest.create();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(5000);
locationRequest.setFastestInterval(1000);
LocationRequest 初始化程序已更改为最新的 Google 播放服务依赖项(> 12.0.0)。现在你可以使用它的 create() 方法来初始化它。例如
LocationRequest request = LocationRequest.create();
在科特林中:
private val locationRequestSettings = LocationRequest.create().apply {
fastestInterval = 1000
interval = 1000
priority = LocationRequest.PRIORITY_HIGH_ACCURACY
smallestDisplacement = 1.0f
}
然后像这样使用:
fusedLocationProviderClient.requestLocationUpdates(
locationRequestSettings,
YourLocationCallback,
null
)