Drupal Location-Gmap Proximity Search

In part 2 of this tutorial, we take a look at the Location Module and Gmap module to create a store locator with a postal code search for our nodes using views and an exposed filter.  With our new view, users can input their postal code to find nodes with locations that are in close proximity to them, which they specify. We even go further to put the locations on a Google map. Enjoy.

Comments

looks like a good first

looks like a good first tutorial, really helpful. couple areas for improvement (video size, aspec ratio, etc.) but i'm looking forward to the next one. is there a way to subscribe to them?

Hi John, thanks for the

Hi John, thanks for the feedback, I'm definitely going to try and improve the issues you mention going forward and hopefully upload the videos in flash rather than quicktime. I haven't used it before but I've been toying with the idea of installing simplenews so people can subscribe and get notified of any new videos. Keep an eye out for it. Pete

hi peter i think if you use

hi peter
i think if you use different player more people can see your tutorial
regards

Thanks. I think you're right

Thanks. I think you're right so I made the switch over to flv files and installed flow player. Let me know what you think. -pete

I tried to install the

I tried to install the Locations module before, the hardest part was the US zip code file is apparently incorrect.

Today I see the Location module lists this web site for database files.

http://download.geonames.org/export/zip/

Do you know if all proximity solutions require import of a zip code file, and why? I am not at all a programmer, it just seems odd that everything else comes from an API or something.

Hi Erich, thanks for the post

Hi Erich, thanks for the post - it's a really good question. The modules need the zip / postal codes to determine a latitude and longitude. However, I guess there is nothing stopping someone from creating a module that hooked into someone else's api and queried their database to return a lat/long... I guess its similar in concept to using the twitter api to return a list of tweets... I don't know of any apis that allow you to hook into them like that for zip / postal codes though...

I think Openlayers provides a

I think Openlayers provides a non zipcode table required solution.

Hardest part about Location module for me is keeping zipcode table up to date via phpMyAdmin.

Your tutorial works though congrats.

Yeah, I know what you mean

Yeah, I know what you mean about keeping the postal codes up to date, I've yet to find a good solution (but admittedly, I haven't spent much time).

thanks for the feedback on the tutorial, I appreciate it!

pete

Great tutorial. Do you know

Great tutorial. Do you know how to make the gmap center on the zipcode entered by the user? Right now, it keeps centering on the default center and the node locations are outside of the viewable map area. I've been trying to find a way to do this for a long time.

Hi Rodney, thanks for the

Hi Rodney, thanks for the feedback! Yes, the gmap should center on the zipcode entered - I would check the macro you've set up in views to make sure it doesn't have a default set to it. Additionally, have you zoomed way out on the gmap to make sure an actual node is being marked on the gmap itself? -pete

Just checked your reply and

Just checked your reply and here’s what I can tell you:

1. I definitely can see the nodes being marked on the gmap. As a temporary fix, I’m making my default zoom far enough out to see the whole US map.

2. I didn’t set any default in views. Not really sure where I should look to check that. I do have a default set for the gmap module under Site Configuration>Gmap. That is the gmap keeps showing no matter what zip code is entered.

Unfortunately, I don’t have this site live (only local) so I don’t have a link to show you how it works. I actually set mine up following this Howto on drupal.org - http://drupal.org/node/359463. This one doesn’t use the view Attachment like you did. So, I think I’m going to create a brand new view and set it up according to your tutorial to see if I have better luck. I’ll let you know if my luck changes following your tutorial!

Thanks again for the follow-up. Let me know if you have any other suggestions based on what I just shared with you. Does your gmap view center on postal codes entered outside of your gmap default center?

Hi Rodney, yeah, that is a

Hi Rodney, yeah, that is a bummer. So couple things come to mind:

  1. Is this happening for every location or just one location?
  2. Does you database have all zipcodes loaded?
  3. Under the views attachment, do you have inherent exposed filters checked?
  4. Under the exposed filter in views for the zip code, do you have a ma to listed?
  5. In views, under gmap attachment, style options, do you have a macro listed? It should just be [gmap ]
  6. Do you have autozoom checked off under the Gmap settings? Let me know what the answers on and we'll keep working on it.

-Pete

OMG! Wow! I just got home

OMG! Wow! I just got home and decided to try out the things you suggested . Nothing worked until I got to #6 - it wasn't checked off. I loaded up my map and it zoomed in! It works like I was hoping! Pete, I can't thank you enough.

Hey, great tutorials! I have

Hey, great tutorials!

I have used the location module on a few sites, so its not new to me, however I haven't had to use proximity search until now. I tried to upload the Canadian postal code database through phpmyadmin, but got the error message saying it was to large of a file.

From what I have read on other sites, they make it sound so simple - simply upload the database and it all works, but its harder then it sounds haha

You mentioned another way to do it in your tutorial, so I was wondering if you could go into more detail on this, or point me in the right direction as I am having a heck of a time...

Hey Justin, thanks for the

Hey Justin,
thanks for the feed back, I appreciate it. Yeah, importing the DB caused me a lot of headaches when I started. What I ended up doing what opening the file up in notepad (I'm on windows) - opening the file took about a minute or so. With it open, I would select about 1/10 of the file and cut (ctrl-x) that part of the script. Then, I would open Phpmyadmin, choose the database, then choose SQL and paste in the sql script that I cut. It was pretty long and tedious.

That said, you can also upload the file easily if you have SSH access or if you are using a shared host, you can probably contact them and they will do it for you.

Hope that helps. Let me know if you need any more help,
pete

I used your copy and paste

I used your copy and paste method, took a bit of time, but it worked great in the end!

Thanks for the quick response.

Awesome videos! I love

Awesome videos! I love them!

bizcommunicate.com

Mark

Followed your tutorial to get

Followed your tutorial to get this function off the ground - thanks!

Is it possible to plot the user entered zip code on the map alongside the results within the map view?

Followed your tutorial to get

Followed your tutorial to get this function off the ground - thanks!

Is it possible to plot the user entered zip code on the map alongside the results within the map view?

Hi Jack, sorry for my late

Hi Jack,
sorry for my late response but I'm glad the tutorial helped. With regards to your question, that is a good one and something I had never thought of... I'd have to look into it when I get some free time. In the meantime, if anyone else has experience with it, I'd love to hear about it.

-Pete

Great tut. A few things to

Great tut. A few things to enhance it would be:
- A message when no results fit the criteria (user experience)
- Add taxonomy as a filter.... so a store locator where store only carry certain items based on a catalog category. I can't get this to work.. any suggestions?

Thanks for the feedback. As

Thanks for the feedback. As for the no result message, here is a thread that addresses that: http://drupal.org/node/701144 - think it should do the trick but I haven't read through all the new comments.

As for the taxonomy filter - how do you have it set up? I can't see it not working but haven't done it myself, do you have any other info?

pete

Hi such an awesome video it

Hi such an awesome video it was extremely helpful...However I am not able to get the proximity distance to show, how did you get the proximity distance to show and sort from closet to furthest?

Thanks a ton!!
Rob

Hi Rob, thanks for the

Hi Rob,
thanks for the feedback! distance/proximity is a field available when creating your view, its under location fields. In the tutorial I choose the address field and distance / proximity -- distance / proximity doesn't show up if you only choose the address field.  You can check it out at about the 2min 50sec mark of the tutorial.

Once you do that, you can add a sort for distance / proximity in views.

Pete

A nice touch is to hide the

A nice touch is to hide the proximity field when the filter hasn't been entered yet by selecting "Count the number 0 as empty" and "Hide if empty". Cleans up the display a little bit.

If anyone is wondering, all

If anyone is wondering, all of this information is still incredibly useful and relevant. Thanks for a great tutorial and pointing me towards the postal code database.

Hey mhzay, thanks for the

Hey mhzay, thanks for the feedback! It's good to know the tutorial is helping out.  I'm planning on creating another follow up to it this weekend to show users how to make sure your visitors properly enter a postal code (it's a bit annoying when someone enters a postal code without a space and they get an empty results message).  There will be another couple gems in the tutorial as well.

[edit] FYI - the new tutorial is up here: http://torontowebsitedeveloper.com/drupal-video-tutorials/improving-ui-d...

Pete

Thanks very much for your

Thanks very much for your videos just wished the quality would be a little better. It is not to be ungrateful but it's not easy to see what's going on but maybe you have the original videos and can save/upload in a better quality, please?

Think this tutorial http://code.google.com/intl/da/apis/maps/articles/phpsqlsearch_v3.html will interest some of you.

I'm surprised that you HAVE to upload diff. zipcode databases and that it's not included in Drupal modules. Maybe some of you can figure out how to use some of the code and include it so people don't have to upload diff. zipcode databases and you also can search for address?

I made this without using ANY drupal map module http://www.tinemuller.dk/new_new_test_drupal/node/1394 but with the code from this tutorial but would love to get this to work with drupal map modules but not beeing a programmer I can't figure out to make such a module myself.

My last map I'm working on is this http://beta.findtoilet.dk/ where I mix drupal 6 map modules and google maps api v3 but would be nice if there could be an official map module to make what I have done with paid help from two diff. programmers. It has taken me years to get here and I'm still struggling.

/Tine

Hi Tine, thanks for the

Hi Tine,
thanks for the feedback - you are absolutely right about the quality. This was one of my first tutorials that I was testing out so it was done with my laptop webcam. I've since bought an HD one and I think the quality has improved.  Have you seen the other tutorials?

Thanks for sharing the link to code.google.com, that is pretty awesome/interesting.

As for inserting the postal codes in the db, i think you will always have to do that. The module doesn't do it automatically because the databases for each geographic area are pretty big / there are hundreds of countries so it doesn't make sense to upload them all. as a result, it's just left to the site administrator. i didnt include it in the video tutorial (because i honestly didnt' know it at the time, i was still pretty new to php/mysql/drupal) but the from the command line, you can use mysql -u [username] -p [database name] [table] < [filename.sql] to dump the file you have into the database. doing so, the .sql file should have the proper insert statements.

with regards to you latest website, what are the 6 drupal mapping modules you used? i haven't finished watching it, but there is a cool drupal mapping video on the drupalcon chicago site which may be of some help to you.

Pete

Your last video is much

Your last video is much better. Thanks a lot.

Is this the video http://chicago2011.drupal.org/sessions/making-beautiful-maps you are talking about?

Maybe this http://svendecabooter.be/comment/1627 would interest some of you.

On http://beta.findtoilet.dk/ I use module Gmap and Locations and a private module called toilet_map.module but the reason why this map looks so great are because we link to javascript files which use Google Maps API v3 code like this:

// add the map interface javascript files and inline code
drupal_add_js($path .'/js/FindToiletMap.js');
drupal_add_js($path .'/js/init_v3.js');
drupal_add_js(_toilet_map_js_event(), 'inline');

/Tine

Hej Hej, thanks for your nice

Hej Hej,
thanks for your nice tutorial. It is possibble that you can explain me how can i solve this with drupal 7 itry all the day but without any success :-(

I have all the german zip codes imported in the zipcode table

Hope you can help me :-)

kind regards
drew29

Hi Drew, I've recently done

Hi Drew,
I've recently done the exactly same thing in Drupal 7 and it was essentially the same steps... where are you getting stuck?

Pete

Nice tutorial. Thanks for

Nice tutorial. Thanks for posting. Keep up the good work :)

Thanks Chris, I appreciate

Thanks Chris, I appreciate the feedback.

Pete

hi yaworsk , i m new in

hi yaworsk ,

i m new in drupal i was impelling search by postal code in Google map.
i was trying to search some restaurants form database for that
i have been created nodes with google map successfully i when i create view for searching on gmap last result query was
" SELECT node.nid AS nid,
location.lid AS location_lid,
'Unknown' AS location_distance
FROM node node
LEFT JOIN location_instance location_instance ON node.vid = location_instance.vid
LEFT JOIN location location ON location_instance.lid = location.lid
WHERE (node.status <> 0) AND (node.type in ('new_node_locations')) AND (1=0) "

i use postal code='C1a 8e2' and distance is 100km .
when i keep distance field is blank it gave all result but not filtered.

thanks

Hi there, Great tutorial on

Hi there,

Great tutorial on this! I'm sure you're sick of helping people out with issues relating to this, but nevertheless, I thought I'd ask.

It seems that every time I try to import the zipcodes.us.mysql file into the database, it doesn't want to enter the data because the table doesn't exist.


ERROR 1146 (42S02) at line 8: Table 'gambit.zipcodes' doesn't exist

The db name is "gambit". As I look at the zipcode file I notice that it doesn't have any "CREATE TABLE" SQL in it... I'm not real familiar with this stuff. Is there something I'm missing? Or do I have to create the table myself first then import the information?

Thanks,
- Doug

Wow, I'm an idiot. I figured

Wow, I'm an idiot. I figured out what the problem was. I suppose it helps if you don't accidentally drop the zipcodes table first.

Hey Doug, good to hear it

Hey Doug,

good to hear it worked out - usually the simpliest of solutions...

pete

This tutorial was the most

This tutorial was the most helpful by far. The 'attachments' functionality is the key to what I was looking for and only found mentioned here. I figured out how to build a simple gmap easily enough, but I needed a list to accompany it... i.e. I needed something useful. Thanks

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options