bracketfire Posted July 16, 2014 Share Posted July 16, 2014 Not quite sure where to post this, but here goes. I'm building a site that uses the Map Marker and Map Markup (Google Maps) modules to geocode addresses and save the lat/long. Is there a selector to find all pages who's lat/long is within a certain radius of another page? Has anyone done any work on such a selector? Maybe something like: $pages->find("template=Place,center=$page,radius=10"); I've found the math to do this, and if nothing like it exists I'll write it and can contribute it back to the community. Don't want to reinvent the wheel if somebody already has done this. Thanks! Link to comment Share on other sites More sharing options...
Craig Posted July 16, 2014 Share Posted July 16, 2014 I implemented a similar thing a while ago and ended up with the code below. I think it was pieced together base on some previous code we had lying around at the company, and I'm not sure why the distance value is so precise at 8.047. It's not a perfect circular distance either, but it seems to work for what was needed at the time. // $lat and $lng should be float values of the location to search $distance = 8.047; //in km $radius = 6371; // earth's radius in km = ~6371 // latitude boundaries $maxlat = $lat + rad2deg($distance / $radius); $minlat = $lat - rad2deg($distance / $radius); // longitude boundaries (longitude gets smaller when latitude increases) $maxlng = $lng + rad2deg($distance / $radius / cos(deg2rad($lat))); $minlng = $lng - rad2deg($distance / $radius / cos(deg2rad($lat))); $query = "coords.lat>=$minlat, coords.lat<=$maxlat, coords.lng>=$minlng, coords.lng<=$maxlng"; In that code, 'coords' is the mapmarker field. 4 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now