Looking for Advice - Proximity searching by address in D6

Events happening in the community are now at Drupal community events on www.drupal.org.
beanjammin's picture

I am working on a project that will, ideally, include proximity searching by address. So far everything I have found is for proximity searching by postal code, except for the gProximity module that appears to do what I want, but is D5 only. If such a creature exists for D6 I haven't managed to find it. I would also like to be able to number the map markers according to the proximity results so that result 1 is numbered 1 on the map, 2 is numbered 2, etc.

Any suggestions on how to go about this would be greatly appreciated.

Failing the existence of a module that already does this, I am wondering about the feasibility of using google's geocoding API to return the lat/long of a user entered address and then use that for doing a proximity search. Has anyone done anything similar? I realise there are scaling issues involved in doing the proximity math on the lat/long on all nodes, however I would expect I can get around this by querying the database to pull in only the nodes within a rough bounding box based on lat/long ranges and then perform the proximity math on only those nodes. All of my nodes are within Canada, which is currently covered by google's geocoding service and I do not expect to have anywhere near the maximum number of queries allowed by google.

Suggestions on how to go about this, what modules to leverage, etc. would be very helpful.

I am currently using Node Locations, but my recent reading suggests that Location CCK is a better future-proof option. Is this a correct reading of the tea leaves?

Many thanks!

Comments

Proximity by address

ac00perw's picture

I created something like this using a sort-of hybrid system:

Location CCK does some lifting for getting longitudes and latitudes of users based on their specific addresses but a custom module does a proximity search with a bounding box using a formula that gets distance in miles to our venues using birds-eye-view and factors in the curvature of the earth. I believe the Location API has this built into it but we had a system in place prior to our use with Drupal 6.

My other custom piece is a script that does a nightly grab of geocodes from Google (they limit you to 15,000 queries a day) based on the venues that sell our beer, which in theory could have been a content type. But since there's about 500k venues we decided not to muck up our regular content with an ever-changing list of venues. We also wanted to throw in door-to-door Google directions for registered users and thus required specific geocodes.

http://www.magichat.net/sipcode/02113

Adam
Magic Hat Brewing Company

Hey Adam, is there any way

ErikU's picture

Hey Adam, is there any way you could point me in the direction on how to create this exposed filter?

A couple of leads

sinmanteca's picture

I'm very interested in this sort of functionality, too. It looks like proximity searching with the Location module has been a challenge for a long time and more recently with Location CCK. However, I definitely think that Location CCK and the accompanying modules will mature eventually to offer address proximity searching along with good integration with Drupal, Views, etc. but I'm skeptical that this will happen quickly.

In the meantime, I've come across a couple of alternatives which I'm considering (but haven't yet tried):

Firstly, there's the phpGoogleStoreLocator (http://crystaldawn.net/). This seems to be a fairly complete and full-featured solution, however, it's not quite a Drupal module -- it seems to have its own installer and admin, so none of your data will be available outside of this application. It also looks like it only receives intermittent attention from the maintainer and there seems to be a number of comments from grumbling users on Drupal.org about unhappy experiences. I'm not so enthusiastic about this one.

More promisingly, CiviCRM (http://www.civicrm.org/) offers a proximity search as one of its Custom Search options. The proximity search works with just an address, province, and country but disappointingly outputs the results as a list (i,e. no map!) by default. Nevertheless, it is possible to map the locations on the list in an extra step, so I expect that it will be possible to redirect the search result immediately to the map instead. Also, the map does not provide incremental numbering, although this may also be configurable with a little tweaking, nor does it output a legend. However, the markers contain info windows with location details and a link to the google maps 'get directions' feature.

If you don't know much about CiviCRM, you'll find that it is a fairly oversized application. In our case, CiviCRM offers some additional features that we may want to utilize within our organization, but otherwise you might find it overkill to set it up just for the purposes of proximity searching. I also understand there to be some integration between CiviCRM and the Location module, however, I have yet to confirm that and I'm not sure if that includes the Location CCK module as well.

Hope that's helpful. I'll post again if I make any headway with my own proximity search plans.

Thanks for the quick responses

beanjammin's picture

Thanks for the quick responses!

I've done a bunch more reading and am going to play with Geo a bit to see whether it gets me closer to what I want. I like the fact that it's based on GIS standards. I'm also going to have a look at gProximity and how much work would be involved in porting it to D6. I'm still very open to other suggestions / ideas.

ac00perw, your site does a lot of what I'm after. Your link also reminded me of a particularly fun trip to Boston... they used to have a kiosk downtown that would produce a map of "attractions" within walking distance. I chose pubs and had a great time :-). I assume you're not in a position to share your custom code?

leinado, my main problem with proximity searching in Location is that it is based on postal/zip codes, and unless you're searching from your own home or office people will rarely know the postal code at their current location. I'm also leary of CiviCRM, it promises a lot of funky functionality but comes with it's own can of worms.

Help from Google provided

pixelmord's picture

Hi,

I did a similar thing for a customer with a hybrid solution attached to typo3.
A tutorial provided by Google ist found here:
http://code.google.com/intl/en-EN/apis/maps/articles/phpsqlsearch.html

I modified that for my purposes, but the code is very much the same. A JavaScript calling a PHP-Script that searches the Database and returning a XML-output that is read back in with the javascript.
That should bring you on the way, some custom markers with a naming convention that includes numbers will get you nice "numbered" markers.

Hope that helps!

Andi

****************
wunderkraut - Da wächst etwas..... www.wunderkraut.com

i used the same tutorial and

tinem's picture

i used the same tutorial and have this from an external database http://www.tinemuller.dk/drupal/node/715 but my plan is to use it INSIDE Drupal and I'm sure it can be done. I think this is what you are looking for, right?

I have made another map here http://www.tinemuller.dk/drupal/Copenhagen_map and it's INSIDE Drupal and it's functioning with the different nodes. Try clicking on the different links under Copenhagens CRUD.

I will soon make the first map INSIDE Drupal and then i will post back here.

I don't use any Drupal module for this because there isn't any at the moment which can make such a site but I don't care the most important thing is that it's functioning. :-)

Good luck and let us hear what you decide.

/Tine

Thanks tinem and pixelmord,

beanjammin's picture

Thanks tinem and pixelmord, the google tutorial looks like it will be really useful.

Tinem, the functionality in your first link is almost exactly what I'm after (the Tivoli Gardens are well serviced ;-). The "you are here" cross hairs are a good touch too.

This Became My First Custom Module

twall411's picture

I Used this tutorial as the basis for my first ever Custom Drupal Module. I am using locations CCK as my data repository. I moved the JavaScript into a separate file and included it in my hook_theme function. It will be used on a site that has members worldwide and serves as a directory for people (nonmembers) to find the nearest service provider. I am now creating the settings form and adding permissions so that I can add a header and footer to the page and change the title. I will then be able to install it on any site and configure it. Thanks for the link to the page it provided the break through that I needed to get things working.

This sounds VERY interesting.

tinem's picture

This sounds VERY interesting. Hope that you will provide a link to your site when you are done, please?

/Tine

Stability/Functionality of the Geo group of modules?

beanjammin's picture

I started looking at the Geo group of modules last night (Geo, Geocoding, and Gmap+Geo) but ran out of energy before I got very far. They appear to be in the early stages of development. Can anyone vouch for their stability / functionality at this point? Is there value in continuing to look into whether they are a better route to go compared to Location?

Right now I have my node locations being geocoded from their address data when the node is submitted by Location, so I have my node's data stored within Drupal using Location's schema. GMap is being used to generate a Google Map when viewing a single node. What I'll need to work on is a module that takes a user supplied address, geocodes it to a lat/long, does the proximity search, and outputs the results to a google map. The methods for doing the proximity searching on lat/long are relatively straight forward, so I'm not overly concerned about how to do that though I do realise that scaling will be an issue.

I am wondering if I can use Geo and Geocoding to replace Location's ability to geocode an address to lat/long on node submission and then whether Geo (and it's use of the MySQL spatial features) will make the proximity calculations easier and/or more scalable if the number of nodes goes up dramatically. I am also hoping I can use Geocoding to take a user submitted address/postal code/ city name/ and convert that to a lat/long for doing the proximity calculations. If I go this route the results would be output using Geo+GMap. Does this approach seem reasonable or have I misunderstood how the Geo modules are intended to be used?

Success!

sinmanteca's picture

Thanks for the tip, tinem and pixelmord. I got my google map Store Locator reading data from my Drupal databases relatively painlessly. tinem, I don't supposed you'd be able to share an example of some of the map customization that have you have done. I'm not exactly a pro with the google maps api (or javascript for that matter!). Thanks again!

I succeeded in making a Google Map without using any Module

tinem's picture

After a lot of hard work I got both maps now functioning INSIDE Drupal and both have connection with the Nodes and link back to each map.

http://www.tinemuller.dk/drupal/Copenhagen_map_radius and http://www.tinemuller.dk/drupal/Copenhagen_map.

But I'm still not sure if I can use it for my project because I'm new to Drupal and just know a little part of what this great CMS can do but really hope I can use it.

But using it this way you have to know about how Google Maps API work and I have used a lot of time figuring this out but got a lot of help from the addresses mentioned down here.

Hopefully there will be Modules in the future for this kind of sites.

http://groups.google.dk/group/Google-Maps-API/web?hl=da and a good forum http://groups.google.dk/group/Google-Maps-API/topics?hl=da.

/Tine

What have you made until now?

tinem's picture
    leinardo wrote: Thanks for the tip, tinem and pixelmord. I got my google map Store Locator reading data from my Drupal databases relatively painlessly. tinem, I don't supposed you'd be able to share an example of some of the map customization that have you have done. I'm not exactly a pro with the google maps api (or javascript for that matter!). Thanks again!

What have you made until now and what do you need help to? Let us see your site, please.

I'm not sure leinado has seen

tinem's picture

I'm not sure leinado has seen my last message and therefore I tried to contact him but I can see that it's impossible. Then I wanted to ask Beanjammin if he has made any progress to his map but see no info about him too.

On my own name tinem people can read info about but I don't have a Contact form and don't know how to get it?

Here is how it stands right now

twall411's picture

This is the link to my development mirror.

Tutorial implemented as a Drupal module.

I have the location module installed and I used a location CCK field in a custom content type. I wrote a custom module and put all of the embedded style information into a service_locator.css. This allows you to customize the look by changing the CSS. I also have the CSS for display of my custom content type associated with this particular map. I put all of the JavaScript into service_locator.js. These two files get loaded onto the page by my theme_service_locator() function. I do the proximity search on the {location} data table and then use {location_instance} to link back to my node which is my custom content type.

Current Status

The API key and several other things are still hard coded in the JavaScript. The text above and below the map can be changed via the administration menu and the title is changed in the Menu administration. As this is my first attempt at writing a module I am sure that there are many improvements that can be made to the coding. I plan to make the JavaScript do an HTTPrequest as it loads so that I can pass the set up configuration to the JavaScript. Then I will be able to add the option to always use miles, always use kilometers, or make it user selectable as part of the admin page for my custom module. I will also be able to add the API key and make the drop down menu for the distances selectable. As you can see I did little to customization to the map itself. It is straight from the tutorial.

Warning!! since the supplied link is to a development site it is subject to periodic outages and odd behavior. Currently there are very few locations outside of the United States so test it with US City,State pairs and Zip Codes.

Share module?

monotaga's picture

Hi, twall411,

I'm interested in implementing a very similar solution on a site, but it seems that the current dev releases of Location/GMap aren't completely there with this implementation. I'd like to contribute to the Location module on this, but I need to get something up and running and what you've done seems relatively quick and quite functional. Would you be willing to share your module code? It'd save me a bit of time from doing the work from scratch, and I could potentially help you with creating some of the admin functionality you're talking about?

I am new to custom Drupal

ErikU's picture

I am new to custom Drupal modules and would love to know how you set this up! I am looking at applying the same type on thing on my site.

If your are looking for

tinem's picture

If your are looking for further explanation how twall411 and I did this kind of maps follow the discussions in this thread http://groups.drupal.org/node/30074#comment-100050

Thanks for the link. Becky

beckyjohnson's picture

Thanks for the link.
Becky

On a site I'm currently

dpatte's picture

On a site I'm currently developing, I now have proximity calculations being calculated by views using the user location. Each user (if he enters an address) can see the distance to the nodes. Its quite cool.

I have two issues though:
1 - If the user provides no location in his profile, the user fallback to static does not seem to work - it always returns a blank distance.
2 - I'd like to be able to setup a range field for each user that they can adjust, so that my views that use proximity can all be filtered within this user-selected range. This may not be difficult using relationships to a user entered value in a content profile item, but it would be nicer if I could keep this value exposed on all my nodes. Any ideas on how I can leave a user field exposed on all my nodes (perhaps in a sidebar area?)

P.S. Im using no special php code or modules, only the stock cck, user location, gmap & views modules.

Proximity from to selection

summit's picture

Hi, I have the following problem.
1) I would like to show the proximity between a postal code or city somebody types in, and the latitude longtitude of a node in my site.
The selecting of nodes could be done through the following:
2a) The node he/she can select by country, then area, then place. The country, area and place somebody selects are taxonomy terms in the site. After selected these, nodes tagged with the specific term show up with the proximity from the typed in postal code.
2b) Or he/she can type in an amount of kilometres/miles and then all nodes in the proximity of this amount will show up with the possibiltiy to set a marge of 10-15 kilometres from the typed in amount of kilometres.

I would very much like to use a location view and a normal view with exposed values of the taxonomy terms, or a combination of both. How would I proceed to get the proximity working from a certain postal code to above 2a and 2b selection-methods?

EDIT: I have allready a "regular" location view with proximity working, but it only works for a postal code within the same selected country. I would very much like to get the 2a, 2b selection methods working.

Thanks a lot in advance for your reply!
greetings,
Martijn

StoreLocator tutorial

tinem's picture

Maybe my subject will interest you http://groups.drupal.org/node/94184.

StoreLocator tutorial

ianraf's picture

I downloaded your storelocator2, now what do I do with that stuff?
I'm not very good with PHP code, but I would do the same thing you did on findtoilet.dk.
As everything is developed in Drupal?
Where all that code is inserted, and as you recall from drupal?

Thank you for your help.

Location and Mapping

Group organizers

Group categories

Wiki type

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: