publiclab / plots2

a collaborative knowledge-exchange platform in Rails; we welcome first-time contributors! :balloon:
https://publiclab.org
GNU General Public License v3.0
961 stars 1.83k forks source link

Changing nearby nodes logic in API's . #4037

Closed sagarpreet-chadha closed 5 years ago

sagarpreet-chadha commented 5 years ago

We have this API for fetching nodes having specific tag :

https://github.com/publiclab/plots2/blob/ba053502ded9ec0163af90d3d7a4cb3eb2a4b74e/app/api/srch/search.rb#L224

This API takes latitude and longitude in the form : query=lat,lon AND them using these coordinates calculates NEAR-BY NODES using this logic :

https://github.com/publiclab/plots2/blob/ba053502ded9ec0163af90d3d7a4cb3eb2a4b74e/app/services/search_service.rb#L104-L108

What do we want ?

We need to take a pair of coordinates in the API URL in the form of :

nwlat=71.01&selat=4.39&nwlng=-172.79&selng=80.33

nwlat=71.01695975726373&selat=4.390228926463396&nwlng=-172.79296875&selng=80.33203125

where nwlat = NorthWest Latitude and selat = SouthEast Latitude and so on ...

Now using these pair of coordinates , calculate all the NODES within the Rectangle Boundary made by these diagonally opposite coordinates .

Happy Coding 😄 ! Thank you !


jywarren commented 5 years ago

Hi, @sagarpreet-chadha would you like to make a task for this or shall I?

sagarpreet-chadha commented 5 years ago

Added to GCI task 😄 👍 !

jonxuxu commented 5 years ago

Hi, I'd like to work on this task. Could you elaborate on this line? I'm not really sure how it works. .where('node.nid IN (?) AND term_data.name LIKE ?', nids, 'lon:' + lon[0..lon.length - 2] + '%')

I've figured out the sql search pseudocode for finding a node but I'm not sure about the syntax when it comes to ruby. So if there's a way to search for latitude and longitude within a range that would be great. SELECT * FROM data WHERE lat < nwlat AND lat > selat AND lng > nwlng AND lng < nwlng

Pointers would be much appreciated!

milaaraujo commented 5 years ago

Reopening because we need to use the same logic in #4128 to update people location endpoint (/api/srch/nearbyPeople)

jywarren commented 5 years ago

great!

On Thu, Jan 3, 2019 at 2:03 PM Camila Araújo notifications@github.com wrote:

Reopening because we need to use the same logic in #4128 https://github.com/publiclab/plots2/pull/4128 to update people location endpoint (/api/srch/nearbyPeople)

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/publiclab/plots2/issues/4037#issuecomment-451243626, or mute the thread https://github.com/notifications/unsubscribe-auth/AABfJ9YZUWZ-NzQOYQkzndVXiYGURvLzks5u_lPvgaJpZM4YxY03 .

sagarpreet-chadha commented 5 years ago

Awesome ! Thank you :)

On Fri, 4 Jan 2019, 00:53 Jeffrey Warren <notifications@github.com wrote:

great!

On Thu, Jan 3, 2019 at 2:03 PM Camila Araújo notifications@github.com wrote:

Reopening because we need to use the same logic in #4128 https://github.com/publiclab/plots2/pull/4128 to update people location endpoint (/api/srch/nearbyPeople)

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub <https://github.com/publiclab/plots2/issues/4037#issuecomment-451243626 , or mute the thread < https://github.com/notifications/unsubscribe-auth/AABfJ9YZUWZ-NzQOYQkzndVXiYGURvLzks5u_lPvgaJpZM4YxY03

.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/publiclab/plots2/issues/4037#issuecomment-451249500, or mute the thread https://github.com/notifications/unsubscribe-auth/AOQoxTATtyQky_HwXjIivUTCXpmGfLJzks5u_ljNgaJpZM4YxY03 .