5

I am trying to build a view that shows the location of any users that are within a certain radius of a node's location. I can get a specific node's location to show up using its nid as the argument, and I can get the users' locations to show up (content profile location), but I can't get BOTH to display on the same map.

I'm thinking the problem is that I only have one option for the datatype that views uses to generate the markers. I've also tried displaying the node's marker through a gmap macro, but when view is displayed, the marker information from the macro is gone, and only the locations rendered by the view's fields are displayed.

2
  • Anyone out there....?
    – user2014
    Commented Sep 12, 2011 at 17:02
  • Did you figure this out, or do you still need assistance? Commented Mar 27, 2012 at 2:43

4 Answers 4

1

This is really a Views question. You can specify a Relationship and a Contextual Filter under the Advanced tab in Views.

I don't know the specifics for Gmap Views, but the principle is the same: You'd make a view of users, with a contextual filter of content:NID. Then you'd create a relationship to nodes based on the location. Gmap Views might give you a way to say 'within x miles of'... This is Views' way of creating a JOIN query.

Then on your content you'd add a Viewfield and tell it to pass the NID to the view. This will attach the view to your node and generate the view of users nearby.

Helpful tutorial about relationships here. Start at about 1:00 if you're impatient. :-)

1

Your problem is double.

Retrieve all nodes 'near' a point.

Here MySQL queries are absolutely not the best choice. You can find example here :

So your MySQL Query would look as ugly as :

SET @lat = $lat;
SET @long = $long;
SET @radius = $radius;

SELECT 
  poi_id 
FROM poi AS p 
WHERE 6371 * 2 * ATAN2 ( SQRT ( ( SIN( ( RADIANS(p.latitude - @lat) / 2 ) * SIN( RADIANS(p.latitude - @lat) / 2 ) + COS ( RADIANS (@lat )) * COS ( RADIANS ( p.latitude ) ) * SIN ( RADIANS(p.longitude - @long) / 2 ) * SIN ( RADIANS(p.longitude - @long) / 2 ) ) ) ,  SQRT ( 1 - (SIN( RADIANS(p.latitude - @lat) / 2 ) * SIN( RADIANS(p.latitude - @lat) / 2 ) + COS ( RADIANS (@lat) ) * COS ( RADIANS (p.latitude) ) * SIN ( RADIANS(p.longitude - @long) / 2 ) * SIN ( RADIANS(p.longitude - @long) / 2 ) ) ) ) < @radius;

To keep Views integration, I would strongly suggest you to switch on Apache SOLR. You'll need it's 3.4 or 4 version. So you can user Apache SOLR Spatial Search ( http://wiki.apache.org/solr/SpatialSearch ). You can check out Apache SOLR / Views integration (drupal.org/project/apachesolr_views )

Your last solution is to use MongoDB which also provides a fast geospatial search. (www.mongodb.org/display/DOCS/Geospatial+Indexing )

Your views problem.

Here you can use ApacheSOLR integration or write your own handler in case of any other solution. You might also bypass views for this specific need. And write a concrete GMAP/Mongo module, for example.

0

Just throwing it out there, but what you can perhaps do is obtain the locations through your Views, and then use a GMaps Macro to draw it manually, either by using a Global Custom Text field with tokens to substitute for the coordinates or some other method.

You can also make a custom query at the template level for the coordinates and again draw it using GMaps Macro (the GMaps module contains great documentation specifying how that can be done).

0

I'm not familiar with a way to achieve this using GMap. But I can at least tell you about one way that works: Use Address Field, OpenLayers, and Openlayers Proximity (also requires Geofield and Geocoder modules). It's not the easiest thing to set up, but is probably the most reliable and robust way to do it (in D7, which I'm assuming here).

In this implementation, you would have Address Fields on users as well as on nodes, and use Geofield+Geocoder to get coordinates for those addresses. You would then set up a view listing users that has the OpenLayers Proximity filter. You will need to feed the proximity filter a location to center around (the location of the node in your example). I'm not sure whether there's a way to set the value of that filter based on a field or argument from the View. If it's not possible, you would need to set the location for the Proximity filter using some custom module code.

In your code you would implement a views hook, obtain the Node ID for the node you want to use as your proximity center, find that node's location, and set the Proximity filter in the view to use that location as its center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.