android - 谷歌地图的地理围栏和准确性,以使用付费版本的谷歌地图 API 定位特定地点
问题描述
我正在尝试开发一个 android 应用程序,我想从 google maps API 获取以下详细信息。
是否可以使用付费版本的谷歌地图 API 为特定地点设置地理围栏(矩形或圆形)?如果是,那么我可以从谷歌地图 API 获得的准确度是多少(特定地点的米或英尺实习生)。
我可以使用谷歌地图 API 读取用户在特定地点停留的时间吗?
当用户在特定地点停留一段时间(如第 2 点所述)时,android 操作系统是否可以在该手机中通知我的应用程序?
对于以上三个功能,我是否必须选择付费版的谷歌地图 API?或者也可以使用免费版本的谷歌地图 API 来完成?
解决方案
对于所有三个问题,答案都是肯定的。第一个,你可以在Geofence的Builder中确定你想要得到的精度,像这样
new Geofence.Builder()
.setRequestId(key)
.setCircularRegion(lat, lang, 150)
.setExpirationDuration(Geofence.NEVER_EXPIRE)
.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER)
.setLoiteringDelay(1000)
.build();
我将精度设置为 150m(您应该知道的一件事是,您设置的精度越高,使用的功率就越大)
对于第二个和第三个,您可以将 TransitionTypes 设置为 Geofence.GEOFENCE_TRANSITION_DWELL 以了解用户是否在一个地方停留一段时间。同时,当这个条件匹配时,你可以使用 PendingIntent 发送一个广播。完整代码如下
Geofence geofence = getGeofence(lat, lng, key);
geofencingClient.addGeofences(
getGeofencingRequest(geofence),
getGeofencePendingIntent(title, location, id))
.addOnCompleteListener(task -> {
if (task.isSuccessful()) {
}else{
}
});
getGeofencingRequest 的代码
private GeofencingRequest getGeofencingRequest(Geofence geofence) {
GeofencingRequest.Builder builder = new GeofencingRequest.Builder();
builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER);
builder.addGeofence(geofence);
return builder.build();
}
getGeofencePendingIntent 的代码
private PendingIntent getGeofencePendingIntent(String title, String location, long id) {
Intent i = new Intent("add your unique ID for the broadcast");
Bundle bundle = new Bundle();
bundle.putLong(Reminder.ID, id);
bundle.putString(Reminder.LOCATION_NAME, location);
bundle.putString(Reminder.TITLE, title);
i.putExtras(bundle);
return PendingIntent.getBroadcast(
getContext(),
(int) id,
i,
0
);
}
推荐阅读
- typescript - 使用混合时,将参数约束为文字值的某个有限联合
- angular - 在 aws s3 上部署时重新加载 Angular 项目时出现 404 错误
- javascript - 音频元素不会播放音频
- wordpress - 将 Drift 和 Hubspot(第三方 JS)添加到 AMP 页面
- python - 在 Django ORM 中分组?
- adobe-analytics - 仅针对 Adobe Analytics 中的特定细分计算的页面停留时间
- python - 在 Python Pillow 中的图像上写 Unicode 文本?
- ios - 核心数据 NSManagedObject - ObservedObjects 未更新
- linux - 与 docker 容器共享虚拟网络
- kubernetes - 在 Kubernetes 中使用 eBPF 进行配置文件