GeoLocation API Calls against an EVE RESTful API

拟墨画扇 提交于 2019-12-11 20:37:04

问题


I easily can store geolocation Data into MongoDB with an Eve RESTful API Server running. So I store data like:

loc : {
  lng: 13.01111,
  lat: 51.01111
}

Validation etc. works nicely.

But: I was unable to find a way to get geolocation data out of the REST API. There are sample queries over there working fine at the command-line, but there seems to be no way to query the API a appropriate way.

  1. Is there a way to throw MongoDB like Queries against the REST API or
  2. which is the prefered way to customize the API for such a purpose.

To make things clear: There is already a 2d index and geoWithin queriey at the mongo-cmd are working fine. It's just about how to query via the REST API.


回答1:


It's not mentioned but it should be supported. I'm not into geo stuff but I just tried to issue a $near query and it returned an operation failure because my database was missing the necessary 2dindex. This means that the command was correctly passed to the database.

If you are using a rest client like Postman the syntax should be something like this (I'm using $near for simplicity):

?where={"loc": {"$near": {"$geometry":{"type": "Point", "coordinates": [13,51]}}, "$maxDistance": 100}}

If you are using app.get method remember to json.loads your query. Hope this helps.




回答2:


Points in MongoDB can be stored as either GeoJSON Point Objects,

 loc : {
            type: 'Point',
            coordinates: [13.0111, 51.0111]
        };

or legacy coordinate pairs.

loc : [13.01111, 51.01111]

The collection should have an index (either 2dsphere or 2d, respectively) to handle queries efficiently.

I'm pretty sure EVE has a built-in geoWithin operator. It's just not working because you're querying an invalid location format.



来源:https://stackoverflow.com/questions/22303175/geolocation-api-calls-against-an-eve-restful-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!