Jump to content
bracketfire

Is There A Distance Radius Selector For Use With Map Marker?

Recommended Posts

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!

Share this post


Link to post
Share on other sites

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.

  • Like 3

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...