nativescript-geofire-plugin
GeoFire for Nativescript - 使用 Firebase 实现Android和iOS的实时位置查询
npm i --save nativescript-geofire-plugin

Nativescript-GeoFire-Plugin

GeoFire for Nativescript - 使用 Firebase 实时位置查询。

该插件的API与geofire的Web版本几乎相同,以增加跨平台代码的重用并便于使用。

安装

tns plugin add nativescript-geofire-plugin

此插件需要将 Firebase 添加到您的项目中。如果尚未添加,可以通过执行以下命令安装一个出色的 firebase 插件 for nativescript

tns plugin add nativescript-plugin-firebase

基本用法

import { NSGeoFire } from 'nativescript-geofire-plugin';

// Here '/geo' is the firebase path which will be used by geoFire for location queries. You can change it to anything.
let geoFire = new NSGeoFire('/geo');

// Set location with key.
geoFire.set(key, [lat, long]).then(() => {
console.log('Geo key is added ');
});

// Get location by key.
geoFire.get(key).then((location)=>{
console.log('latitude and longitude ', location[0], location[1]);
});

// Remove location stored with specified key.
geoFire.remove(key);

// Location based query.
let query = this.geoFire.query({
center: [lat, long],
radius: radius // in km
});

// Various events triggered by geoFire for the query being executed.
query.on('key_entered', (key: string, location: number[]) => {
console.log('key entered ', key, location);
});

query.on('key_exited', (key: string) => {
console.log('key exited ', key);
});

query.on('key_moved', (key: string, location: number[]) => {
console.log('key moved ', key, location);
});

query.on('ready', () => {
console.log('GeoQuery has loaded and fired all other events for initial data');
});

API

目前,请参阅index.d.ts文件中的API。