简体   繁体   English

如何根据android中的用户位置从Firebase数据库中检索数据?

[英]How to retrieve data from Firebase database based on user location in android?

I want to develop an android app, in which if an user enters a specific area, the id of that area is passed to Firebase database and some values(couple of strings and images) are retrieved and is displayed in the android app.我想开发一个 android 应用程序,如果用户进入特定区域,该区域的 id 将传递到 Firebase 数据库,并检索一些值(几个字符串和图像)并显示在 android 应用程序中。 I have seen Google's Geofence API is used to identify whether an user enters a area or not, and if entered, a notification is triggered.我见过谷歌的Geofence API是用来识别用户是否进入一个区域的,如果进入,就会触发通知。 In my case, I don't want to send notifications but retrieve specific set of data from Firebase and display it on the app.就我而言,我不想发送通知,而是从 Firebase 检索特定数据集并将其显示在应用程序上。

Is it possible with Google's Geofence API, and if so how could it be implemented?谷歌的地理围栏 API 是否可行,如果可以,如何实现? Some tutorial or links to videos explaining that would be mostly appreciated.一些教程或视频的链接解释这将非常受欢迎。 And are there any options other than Geofence API that does what I want?除了 Geofence API 之外,还有其他选项可以满足我的需求吗?

I'm not sure about any alternative solution, but you're describing a perfect use case for Google's Geofence API.我不确定任何替代解决方案,但您正在描述 Google 的地理围栏 API 的完美用例。 The following example https://developer.android.com/training/location/geofencing.html#java will show you how to:以下示例https://developer.android.com/training/location/geofencing.html#java将向您展示如何:

First, use Geofence.Builder to create a geofence, setting the desired radius, duration, and transition types for the geofence.首先,使用 Geofence.Builder 创建地理围栏,为地理围栏设置所需的半径、持续时间和过渡类型。 For example, to populate a list object例如,要填充一个列表对象

... ...

The following snippet uses the GeofencingRequest class and its nested GeofencingRequestBuilder class to specify the geofences to monitor and to set how related geofence events are triggered:以下代码段使用 GeofencingRequest 类及其嵌套的 GeofencingRequestBuilder 类来指定要监控的地理围栏并设置相关地理围栏事件的触发方式:

... ...

Define an intent for geofence transitions定义地理围栏过渡的意图

I won't copy/paste the examples further from the offical documentation, but once you have a basic setup going you can contact Firebase as you would normally do.我不会从官方文档中进一步复制/粘贴示例,但是一旦您进行了基本设置,您就可以像往常一样联系 Firebase。

If you're stuck, please provide some code showing how far you've got and you'll surely get some more specific help.如果您遇到困难,请提供一些代码来显示您已经走了多远,您肯定会得到一些更具体的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM