Hi,

how to setup a view filtering node's via proximity? i just wanna insert an city or zipcode (exposed filter) and then the view should show all node in a range of 100 km.

Comments

danielb’s picture

OK I've made a proximity search module - but I haven't released it because I'm not really sure how people would want to configure it, or what they would want to use it for.

Firstly you need the person's country, because a ZIP/city is almost meaningless to google without the country. I use GeoIP to determine the person's location based on their IP address - however on some ISPs it doesn't work so you need to provide a 'country' select box anyway :(

So once you have the latitude/longitude of the user, you need to do a really cool query like this

$query = "
SELECT l.eid, l.latitude, l.longitude, SQRT( POW( 69.1 * ( l.latitude - ".$latlon['lat']."
) , 2 ) + POW( 69.1 * ( ".$latlon['lon']." - l.longitude ) * COS( l.latitude /
57.3 ) , 2 ) ) AS distance FROM {location} l
AND l.latitude IS NOT NULL AND l.longitude IS NOT NULL
ORDER BY distance ASC
";

unfortunately you can use "limit" clause in this SQL query without royally stuffing it up, so you need to limit your results with a for loop.

Then you might want to decide on a distance cutoff such as 100km (who cares about stuff that's over a 100k away??)

And then you need to set the zoom of the map itself, based on the distance of the nearest nodes to the user - this took a bit of guessing based on the scale of the maps and some trial and error.

You can do all of these calculations in the submit function of the form - save them into a session variable, and redirect to the gmap view.

Now you need to molest your map based on the settings you worked out before. The Gmap does not provide any hooks for molesting the map upon loading a view. So you must copy theme_views_view_gmap() from gmap_views.module into your template.php and of course change 'theme' to your theme name. In the bottom of this function you can manipulate the map array using your session values.

I'm not sure if this is the sort of answer you are after - if anybody is interested in my preliminary gmap locator module I can post it up - but it is probably unlikely you would be able to stick it into your site and use it without changing the code to suit your purposes.

Some examples of sites with drupal gmap/location postcode proximity finder:

http://golfqueensland.org.au/clubs - look for the 'find a club by postcode' section near the bottom of the page. Example valid postcodes: 4000, 4060, 4211, 4120
http://sunfx.com.au/en-au/customer - this site might actually not let you use it if you're outside Australia - can't remember, but Australian postcodes are valid (e.g. 2000 - sydney, 3000 - melbourne, 4000 - brisbane)

dannypfeiffer’s picture

Thanks for the info.

yesct’s picture

I'm looking for something much simpler. I want to have a few nodes a "club" type. Right now, I'm testing this only in one state in the USA. Use a zip for each club. And be able to list 4 other nearest clubs. If anyone can point me to a documentation page, or a IRC log or something I would really appreciate it. (I have 6.5 with location 6.x-3.0-rc1, cck 6.x-2.0-rc10, and views 6.x-2.0-rc5 installed.)

I'm worried that I wont be able to test this out because, in my modules admin page under location it says: "Location Search 6.x-3.0-rc1 A custom search page for locations.
This version is incompatible with the 6.5 version of Drupal core." But I'm hopeful that what I want is simple enough that I might not need that "location search" enabled to do it.

Thanks a ton, Cathy

skyredwang’s picture

subscribing

henrijs.seso’s picture

What I would want (and many others I suppose) is gmap on which I could click and a marker of human would show up and 5 km around it node locations would pop up.

How about that? Neat, simple and clean.

daneyuleb’s picture

I want what the original poster seems to--just give me a view containing all nodes that are within X distance of a specified zip code or city. Don't really need it shown on a map...I just want it as a view filter.

yesct’s picture

I think this is now part of the dev version. But where are the instructions for how to set settings, configure it, and insert a search?

daneyuleb’s picture

Still wondering how to do this on 6, with views 2. If it's possible with the latest dev, it doesn't seem obvious at all.

Basically--how to create a view with an exposed filter for a location field (ie, zipcode) and show only nodes or users within a specified radius (ie, 100 km).

-Daniel

mtndan’s picture

See #329802: how to code proximity queries in php for another way to do this using a computed cck field

daneyuleb’s picture

Thanks for the computed field link. My location info is on the profile, not the nodes themselves, so I need to figure out how to alter that code to make the computed field code use that. Still, while helpful, I don't think it will do what is ultimately needed by most people--a dynamic exposed filter that results in a view of users or nodes within a given radius.

For those who used the 5.x version, was that what was available? A view that basically let you put in a zip code and a distance in an exposed filter, and then displayed a list of nodes within the specified radius? Is that what was available, or did it work some other way?

Madapple’s picture

looking for this function as well.

bdragon’s picture

yesct’s picture

Status: Active » Closed (fixed)

see the progress at the issue in #12