Hello,

I am looking for a solution to get a list of users which locations are within a certain distance of a point. I am using OpenLayers, Geofield, Geophp in Drupal 7.

I found a possible solution using OpenLayers Proximity module but I would prefer to avoid using it because :
- It uses the geocoder service api from Google, and I rather avoid that, I could (hope) rich the query limit quickly
- It integrates the functionnality with views, and again I may have too many queries which are going to get problematic with the load of views.

From that point, I am looking into OpenLayers distanceTo (ex.: http://gis.stackexchange.com/questions/25685/distanceto-is-giving-wrong-...) method or geoPHP buffer propertie.

My first question would be to know what is the best approach to get what I want with minimal loading ? Any other suggestions welcomed

The second question would be about code, can anybody could give me a hint on how to achieve my goal ?

$json ='{
   "type": "MultiPoint",
   "coordinates": [[100.0, 0.0], [101.0, 1.0], [102.0, 2.0]]
}';
$multipoint = geoPHP::load($json, 'json');

//The idea i got is to define the point to get distance from
$my_point = geoPHP::load('point(103.0 3.0)','wkt');

//Then add it to the $multipoint variable
$multipoint.add($my_point);

//Make the newly added point as the center
$multipoint_points[0].setCenter();

//Finally use the buffer propertie to limit the distance from center - in meters would be great
$points_within_distance = $multipoint->buffer(5);

//Display all points within 5km of $my_point 
print_r($points_within_distance);

I know the code doesn't work but I want to show my logic. Anybody could give some help on how to use the buffer propertie and get array elements within the distance from a defined point ?

Best Regards,
Clem

Comments

phayes’s picture

Hi there,

I would definitely check out the work being done for proximity filters and sorts in the 2.x of the geofield module. I think a lot of this work has already been done. THe issue is here: #1469956: [Meta] - Improve Views-powered Geofield proximity searches

If you want to do it using geoPHP instead (not recommended), you would use buffer to transform a point into a polygon then the "contains" method to check to see if another point is within said polygon. This would require installation of the GEOS PHP extension. However, my recommendation is to use the geofield proximity views stuff.

krem’s picture

Status: Active » Closed (fixed)

Hi there,

Thanks for the advice, I had a try and so far so good, geofield 2 is what I need. I also found some guidance to perform a proximity search through mysql, so if I see that views loading is too important I can try to perform the search directly with http://www.movable-type.co.uk/scripts/latlong-db.html

Best Regards,
Clem