java Android:制作地理围栏的简单方法?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12028928/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 07:20:41  来源:igfitidea点击:

Android: Simple way to make a geofence?

javaandroidgeolocationlocationlocation-based-service

提问by thedeepfield

I'm new to Android development and am creating an app that allows a User to create a Geo fence around a specific location for reminders. For example: Making a geofence around a grocery store to remind the user as he enters to pick up Orange Juice.

我是 Android 开发新手,正在创建一个应用程序,允许用户围绕特定位置创建地理围栏以进行提醒。例如:在杂货店周围设置地理围栏以提醒用户进入取橙汁。

Does anyone know of a tutorial that could help in developing something like this?

有谁知道可以帮助开发这样的东西的教程?

回答by Ginger McMurray

AFAIK there are no tutorials for geofencing, but it's pretty simple (assuming you want a circular fence).

AFAIK 没有地理围栏的教程,但它非常简单(假设您想要一个圆形围栏)。

  • This tutorialwill tell you how to get the user's location
  • Any of theselinks will show you how to calculate the distance between their current location and the centerpoint for their fence
  • Calculate their distance from the center at regular intervals. I'd let them set the interval through a settings screen and start with a default around five minutes because anything more than that is a hefty battery drain. Store that distance every time you get it.
  • If their last distance compared to their new distance crosses the boundary, perform your action. For instance, I worked on an app that would alert a parent if the child left a friend's house or arrived at school.
  • 本教程将告诉你如何获取用户的位置
  • 这些链接中的任何一个都将向您展示如何计算其当前位置与其围栏中心点之间的距离
  • 定期计算它们与中心的距离。我会让他们通过设置屏幕设置时间间隔,并从大约五分钟的默认值开始,因为除此之外的任何事情都会消耗大量电池电量。每次到达时都存储该距离。
  • 如果他们的最后距离与新距离相比越过边界,请执行您的操作。例如,我开发了一个应用程序,如果孩子离开朋友家或到达学校,它会提醒父母。

回答by Ejmedina

You can use the new GeoFence class released at Google IO 2013:

您可以使用在 Google IO 2013 上发布的新 GeoFence 类:

http://developer.android.com/reference/com/google/android/gms/location/Geofence.html

http://developer.android.com/reference/com/google/android/gms/location/Geofence.html

回答by Jaimoto

回答by user3103443

An new API called Proxim.io was recently developed that serves your purpose. The website is www.proxim.io. Here is a quote from the developer documentation:

最近开发了一个名为 Proxim.io 的新 API,可以满足您的目的。该网站是 www.proxim.io。这是开发人员文档中的引用:

Proxim.io is a platform for delivering relevant messages to your application users. Messages that are delivered based on real-time location, topics of interest, and geo-triggers. Messages can be delivered to a device via Push, or can be routed to a software system through an API (Web Events).

Proxim.io 是一个向您的应用程序用户提供相关消息的平台。基于实时位置、感兴趣的主题和地理触发器传递的消息。消息可以通过 Push 传递到设备,也可以通过 API(Web Events)路由到软件系统。