Drupal 6 - best way to display GMap tied to Location
HelluvaEngineer - March 26, 2009 - 00:40
I hope this isn't an obvious question, but I'm a newb at Drupal and I've spent WAY too much time trying to get this to work. Please help. All I want to do is take a Location in a CCK content type, and display it on a GMap. I need it to geocode, not depend on coordinates.
I've read many posts and looked at many modules, but I can't find a straightforward way to do this. It looks like there were some options for v5 but they were never updated.
What's the current "best way" to accomplish this. By "best", I probably mean simplest.
TIA, HE

This seems to address the
This seems to address the issue you raise:
http://drupal.org/node/386848#comment-1368296
----------------------------------------------------------------------
http://classicvinyl.biz
http://music.classicvinyl.biz
http://association.drupal.org/user/1207
Thanks for the link! I'll try
Thanks for the link! I'll try this tomorrow. I quick glance indicates that it's similar to my current View, but I must have knackered a setting.
There is also
There is also this:
http://alanpalazzolo.com/node/13
I have not tried it but it looks interesting and may be another way of doing what you want.
----------------------------------------------------------------------
http://classicvinyl.biz
http://music.classicvinyl.biz
http://association.drupal.org/user/1207
No luck. This is really
No luck. This is really driving me mad.
I've created the view and the geocoding is working. How do I get the view to automatically display in my CCK content type? I don't see how they are associated (what triggers the view to display).
I think I understand what you
I think I understand what you need. If so, you can insert the code directly into node.tpl.php. Have a look here:
http://drupal.org/node/267568#comment-942586
This worked for me; I used the contemplate module to create a node template and inserted the code therein.
You can wrap the code in to facilitate styling with CSS.
----------------------------------------------------------------------
http://classicvinyl.biz
http://music.classicvinyl.biz
http://association.drupal.org/user/1207
ok, this worked
I was able to get this to work. However, I had to change it a bit, so that the lat and long data came from $node->location_field[0]['latitude'], etc. The example seems to assume global $latitude and $longitude values, which did not exist in my environment.
If I can get additional info to display (such as address info in the map bubble), I will follow up with that code.
Thanks for all the help. I'd still like to see those other methods - I think they would help others because this doesn't seem to be well documented in v6.
I ran into the same problem... I think...
Hey there,
Let me know if this is the scenario you're looking for:
You want to add a location (a restaurant, or venue, as it was in my case). You put location name in, then want to put in the state/province, then city, then street address. No need to put in coordinates, or any of that bull.
And then you want it to automatically show a Google Map to that location.
I have something set up on my Drupal site set up like this and it works really well. Is this what you're looking for?
yes!
Yes! That's exactly what I want to do.
Thinking about this last night I realized the disconnect in my head: from the examples I've seen, it looks more like Views is intended to aggregate various pages / nodes. It dynamically builds the SQL to join all of the items up, filter, and then list links to matching content. It seems like it's intended to run at its own URL, as a standalone item. Is this correct? If so, it doesn't seem like the mechanism I need to do what you described:
* Display a Gmap on each node that has Location info *
Please post any examples that you can. I would be very interested in seeing your solution.
TIA, HE
Have you enabled the location
Have you enabled the location settings for the content type you have created? If you do not do that, the map will not display.
----------------------------------------------------------------------
http://classicvinyl.biz
http://music.classicvinyl.biz
http://association.drupal.org/user/1207
I *think* I did, but I'm not
I *think* I did, but I'm not sure what you're asking. The actual location field in the content type is displaying. It's showing the location, along with a link to a Google map. In place of the link, I want an actual map. Am I missing the point of your question?
I am not sure... can you
Content types >> edit >> locative settings
Can you append a screen shot here of what you have now??
----------------------------------------------------------------------
http://classicvinyl.biz
http://music.classicvinyl.biz
http://association.drupal.org/user/1207
hmmm...I have a screen cap
hmmm...I have a screen cap but I don't see an option to upload the image on here. Do I need to host it remotely?
If possible, please do. It
If possible, please do. It will be easier to see what is going on.
----------------------------------------------------------------------
http://classicvinyl.biz
http://music.classicvinyl.biz
http://association.drupal.org/user/1207
Using GMap, CCK, and Contemplate
Hey man, (or woman, I guess...)
Sorry I didn't get back to you earlier. Here's how I've set my system up:
1) Make a CCK content type called Location and create text fields for addresses (in my case, I have province, city, address). You can also add other fields for this location, like phone number, description, etc... but the addresses are integral to getting maps to work.
Screenshot: http://www.trevorkjorlien.com/storage/drupalmap4.png
2) Download and install the GMapEZ Module (http://drupal.org/project/gmapez). You'll also need to get a Google Map Key, which you can find the link for and insert at "admin/settings/gmapez" once module is installed.
3) Next, install Contemplate (http://drupal.org/project/contemplate). Once installed, we're going to create a template for the Location content type...
4) For the Body output, here's my code and I'll explain it a bit:
<?php
if ($node->field_address[0]['view']) {
$address = drupal_urlencode(check_plain($node->field_address[0]['value']));
$city = drupal_urlencode(check_plain($node->field_city[0]['value']));
$province = drupal_urlencode(check_plain($node->field_province[0]['value']));
echo gmapez_add_script();
?>
<div style="float: left">
<div class="GMapEZ GLargeMapControl GMapTypeControl GScaleControl GOverviewMapControl"
style="width: 300px; height: 200px;"><a href="http://maps.google.com/maps?q=<?=$address ?>,%20<?=$city ?>,%20<?=$province ?>,%20<?=Canada ?>"></a></div>
</div>
<?php } ?>
The variables ($address, $city, $province) store in the values from the CCK text fields we made in Step 1. Just make sure the field names match the ones you made. In my case, I live in Canada where we pompous folk use provinces. You might live in the US, so could be states for you.
After the PHP script comes the DIVs to place the map on the template. The DIV class stuff controls the display of the map controls, terrain, etc...
The anchor tag brings in the variables. You can see $address, $city, $province. Because all our locations are all in Canada, we had no need to make a CCK field called $country, because it would be needed to put "Canada" in each time. If you live in the US, you would put United%20States, I assume. Don't quote me on that one there. If you have locations in different countries, make a field for it, and add the variables as needed (should be pretty straightforward by now).
5) OK, I think that's it. Let's go add a new Location.
For our site, we wanted to do Restaurant Reviews, Show Reviews, etc... So I thought, wouldn't it be cool to just type in the name of the location that the article references and automatically bring up the map for it.
6) So make a new (or take an existing) content type, go to Manage Fields, and you'll see the Existing Field area, add a Node Reference (Location). Press Save.
On the next page, make sure you're Location content type is referenced. Save field settings.
EDIT: Forgot about this. And it's important. For this content type, you also need to go to Display fields, and for the Location field, you need to set it to "Full Node". This will show the map, rather than just a link.
Now when you add a Restaurant Review, you'll see a field for location. Start typing the name of it, and Drupal autocompletes the names that you've added.
Screenshot: http://www.trevorkjorlien.com/storage/drupalmap3.png
When you're done making your content, you should see a Google Map of that location. Note that because the location is a node, it will show up inside of content types, or stand on its own. Standing on its own node could be useful for, let's say a venue. It'll show the map of the venue, then all the contact info for it, but then below maybe a list of related shows or articles. Just a thought...
Screenshot: http://www.trevorkjorlien.com/storage/drupalmap2.png
Let me know if you run into any problems. I haven't had to set this up in a few months, so I could have missed a step somewhere. Also, when you're working in Contemplate, here's the customization options for the map:
http://n01se.net/gmapez/