GeoLocation API Calls against an EVE RESTful API

2019-08-16 04:45发布

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.

2条回答
Deceive 欺骗
2楼-- · 2019-08-16 05:05

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.

查看更多
ゆ 、 Hurt°
3楼-- · 2019-08-16 05:22

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.

查看更多
登录 后发表回答