Page 1 of 1

Find database entries in a radius

Posted: Fri May 09, 2014 1:46 pm
by Bill Clanton

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.


Find database entries in a radius

Posted: Fri May 09, 2014 3:32 pm
by Kateryna Grynko

Hi Bill,

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


Find database entries in a radius

Posted: Sat May 10, 2014 4:47 am
by Bill Clanton

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


Find database entries in a radius

Posted: Mon May 12, 2014 8:14 am
by Kateryna Grynko

Hi Bill,

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


Find database entries in a radius

Posted: Mon May 12, 2014 1:56 pm
by Bill Clanton

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?


Find database entries in a radius

Posted: Mon May 12, 2014 2:58 pm
by Bill Clanton

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


Find database entries in a radius

Posted: Mon May 12, 2014 3:05 pm
by Evgene Karachevtsev

Hello Bill,

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