Skip to content
This repository has been archived by the owner on Jan 10, 2019. It is now read-only.

Find the nearest item with given geo point #3

Closed
bruin2003 opened this issue Oct 11, 2013 · 2 comments
Closed

Find the nearest item with given geo point #3

bruin2003 opened this issue Oct 11, 2013 · 2 comments

Comments

@bruin2003
Copy link

Is there a way to query the nearest item stored in dyanmoDB with a given geo point? Let's assume that we have 50k items of interests stored in dynamoDB and i need to find the closet one with the given geo point. What is the best way to accomplish this?

@lloydaduke
Copy link

After having implemented a proximity search utilizing pieces of the API
(which is nothing more than the radius search in the example customized
with our data and business logic). It would seem to me the simplest way
find the closest point would to write your own version of the filter used
in GeoDataManager.

In GeoDataManger the filter method handles both rectangle and radius
searches. If the request is for a radius search it

Determines the S2LatLng of the center point and the radius used for the
query.
For each item returned from the geo query:
Create a S2LatLng object from the result.
If the distance between the result and the center point is less than or
equal to the given radius add it to the results.

You would just have to change the return logic a bit (this time in pseudo
code for easier reading).

SHORTEST_DISTANCE = null
ITEM_TO_RETURN = null

for each RESULT in QUERY_RESULTS

CURRENT_DISTANCE = CENTER_POINT.getEarthDistance(RESULT)

if SHORTEST_DISTACE is null
SHORTEST_DISTANCE = CURRENT_DISTANCE
ITEM_TO_RETURN = RESULT

else if CURRENT_DISTANCE is less than SHORTEST_DISTANCE
SHORTEST_DISTANCE = CURRENT_DISTANCE
ITEM_TO_RETURN = RESULT

Take note of the getEarthDistance method in S2LatLng. All you have to do is
utilize that method to determine the shortest distance and the return
object.

Hope that helps.

On Fri, Oct 11, 2013 at 5:42 PM, bruin2003 notifications@github.com wrote:

Is there a way to query the nearest item stored in dyanmoDB with a given
geo point? Let's assume that we have 50k items of interests stored in
dynamoDB and i need to find the closet one with the given geo point. What
is the best way to accomplish this?


Reply to this email directly or view it on GitHubhttps://github.com//issues/3
.

@yosuke-matsuda
Copy link
Contributor

The library currently doesn't support the feature, but you can implement it by following @lloydaduke's suggestion. Thank you, @lloydaduke !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants