Bill Clanton
Posts: 0
Joined: Wed Apr 23, 2014 2:48 pm

Find database entries in a radius

In my photo sharing app, i have it saving the lat and lon with each photo. My next step is to add a search function where users can find other photos that were posted near their location.

So basically, the search would grab the user's current location, and then show all photos taken with in a 1 mile radius. I've looked at a few tutorials, but i can't seem to see how to make it work.

Any help is appreciated.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Find database entries in a radius

Hi Bill,

Hope this discussion will help you: https://getsatisfaction.com/apperyio/...

Bill Clanton
Posts: 0
Joined: Wed Apr 23, 2014 2:48 pm

Find database entries in a radius

I'm lost as to how i would make that work with a database query.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Find database entries in a radius

Hi Bill,

Here is all the information: http://docs.appery.io/documentation/b...

Bill Clanton
Posts: 0
Joined: Wed Apr 23, 2014 2:48 pm

Find database entries in a radius

ok, that makes better sense. do i have to have the lat and lon both as comma separated entries in the database? or is there a way to query based on them being in different columns?

Bill Clanton
Posts: 0
Joined: Wed Apr 23, 2014 2:48 pm

Find database entries in a radius

i got it all figured out. I just had to grab the lat and lon that i was already storing in the local storage.

var latvalue = localStorage.getItem("lat");
var lonvalue = localStorage.getItem("lon");

return '{"location" : {"$nearSphere" : ['+ latvalue +', '+ lonvalue +'],"$maxDistanceInMiles" :80}}';

this is now working perfectly. I just had to also change my database to include a "location" column rather than having separate lat and lon columns.

thanks

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Find database entries in a radius

Hello Bill,

Thank you for the update. Let us know if you need any further help.

Return to “Issues”