WildGeo Library

Realtime location queries with Wilddog

License

License

MIT
Categories

Categories

Geo Business Logic Libraries Geospatial
GroupId

GroupId

com.wilddog
ArtifactId

ArtifactId

wildgeo
Last Version

Last Version

2.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

WildGeo Library
Realtime location queries with Wilddog
Project URL

Project URL

https://github.com/WildDogTeam/lib-android-wildgeo.git
Source Code Management

Source Code Management

https://github.com/WildDogTeam/lib-android-wildgeo

Download wildgeo

How to add to project

<!-- https://jarcasting.com/artifacts/com.wilddog/wildgeo/ -->
<dependency>
    <groupId>com.wilddog</groupId>
    <artifactId>wildgeo</artifactId>
    <version>2.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.wilddog/wildgeo/
implementation 'com.wilddog:wildgeo:2.0.0'
// https://jarcasting.com/artifacts/com.wilddog/wildgeo/
implementation ("com.wilddog:wildgeo:2.0.0")
'com.wilddog:wildgeo:jar:2.0.0'
<dependency org="com.wilddog" name="wildgeo" rev="2.0.0">
  <artifact name="wildgeo" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.wilddog', module='wildgeo', version='2.0.0')
)
libraryDependencies += "com.wilddog" % "wildgeo" % "2.0.0"
[com.wilddog/wildgeo "2.0.0"]

Dependencies

compile (1)

Group / Artifact Type Version
com.wilddog.client : wilddog-sync-android jar 2.3.0

Project Modules

There are no modules declared in this project.

WildGeo 实时位置查询Android lib库

WildGeo是基于地理位存储和查询的Android library,它基于wilddog数据库,将位置信息存储数据到wilddog数据库中,可以实时查询指定地理位置的周边信息。

WildGeo有Objective-CJavaScript客户端。

场景示例

假设你在开发一个点评酒吧的应用,在/bars/<bar-id>节点下存储酒吧相关的信息(名称,营业时间,价格范围),你想增加一个查询附近酒吧的功能,WildGeo刚好适合。你可以用wildgeo存储地理信息,酒吧id作为健值,WildGeo 可以查询附近的酒吧Id,然后再获取酒吧的相关信息。

整合WildGeo到android项目

添加wildgeo依赖到gradle.build

dependencies {
    compile 'com.wilddog:wildgeo:2.0.0+'
}

入门

WildGeo使用野狗数据库,你可以从这里 注册一个免费体验账号。

初始化WildGeo

如果应用中还没有初始化过Wilddog Sync,那么应该先进行初始化,参考文档:https://docs.wilddog.com/sync/Android/quickstart.html

WildGeo对象用于数据的存储和查询,为了创建一个WildGeo实例,你需要先创建一个Wilddog的引用。

SyncReference ref = WilddogSync.getInstance().getReference("/path/to/geodata");
WildGeo wildGeo = new WildGeo(ref);

记得添加安全规则

设置位置数据

WildGeo中你可以根据key值查询和设置地理位置,通过传入key和GeoLocation(latitude,longitude)参数调用setLocation方法:

wildgeo.setLocation("wilddog-hq", new GeoLocation(37.7853889, -122.4056973));

检测是否成功保存数据到服务器,可以添加wildgeo.CompletionListener 方法:

wildgeo.setLocation("wilddog-hq", new GeoLocation(37.7853889, -122.4056973), new WildGeo.CompletionListener() {
    @Override
    public void onComplete(String key, SyncError error) {
        if (error != null) {
            Log.d(TAG, "There was an error saving the location to wildgeo: " + error);
        } else {
            Log.d(TAG, "Location saved on server successfully!");
        }
    }
});

删除位置信息 removeLocation方法:

wildgeo.removeLocation("wilddog-hq");

获取位置信息

wildgeo.getLocation("wilddog-hq", new LocationCallback() {
    @Override
    public void onLocationResult(String key, GeoLocation location) {
        if (location != null) {
            Log.d(TAG, String.format("The location for key %s is [%f,%f]", key, location.latitude, location.longitude));
        } else {
            Log.d(TAG, String.format("There is no location for key %s in wildgeo", key));
        }
    }

    @Override
    public void onCancelled(SyncError syncError) {
        Log.d(TAG, "There was an error getting the wildgeo location: " + syncError);
    }
});

Geo查询

WildGeo能够查询指定地理区域的所有keys,实时更新数据和触发相关联的事件。 GeoQuery可以改变中心区域大小。

// creates a new query around [37.7832, -122.4056] with a radius of 0.6 kilometers
GeoQuery geoQuery = wildgeo.queryAtLocation(new GeoLocation(37.7832, -122.4056), 0.6);

geo queries 事件

geo query可能触发5种事件:

  1. Key Entered: 符合查询条件的location key.
  2. Key Exited: 不再符合查询条件的location key.
  3. Key Moved: 符合查询条件的location key变化时.
  4. Query Ready: 所有数据加载完成和事件触发完成.
  5. Query Error: 执行查询出错时触发.

GeoQueryEventListener:

geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
    @Override
    public void onKeyEntered(String key, GeoLocation location) {
        Log.d(TAG, String.format("Key %s entered the search area at [%f,%f]", key, location.latitude, location.longitude));
    }

    @Override
    public void onKeyExited(String key) {
        Log.d(TAG, String.format("Key %s is no longer in the search area", key));
    }

    @Override
    public void onKeyMoved(String key, GeoLocation location) {
        Log.d(TAG, String.format("Key %s moved within the search area to [%f,%f]", key, location.latitude, location.longitude));
    }

    @Override
    public void onGeoQueryReady() {
        Log.d(TAG, "All initial data has been loaded and events have been fired!");
    }

    @Override
    public void onGeoQueryError(SyncError error) {
        Log.d(TAG, "There was an error with this query: " + error);
    }
});

removeGeoQueryEventListenerremoveAllListeners可以移除GeoQuery的监听事件。

Updating the query criteria

GeoQuery查询区域可以通过setCentersetRadius改变,在变化过程中Key exited 和 key entered events将会被触发,但是移动事件是独立触发的。 当用户的视角切换后,更新查询到可见区域是很有用的。

版本升级

从2.0.0版本开始,WildGeo使用2.x版本的Wilddog Sync。如果应用中在使用旧版本的wilddog,可以使用1.x版本的wildgeo.
从2.0.0版本开始,WildGeo不再支持非Android环境。

更多示例

这里分类汇总了 WildDog平台上的示例程序和开源应用, 链接地址:https://github.com/WildDogTeam/wilddog-demos

License

MIT http://wilddog.mit-license.org/

感谢 Thanks

We would like to thank the following projects for helping us achieve our goals:

Open Source:

com.wilddog

WildDogTeam

国内领先的实时后端云

Versions

Version
2.0.0
1.0.0