<iframe>tag. This method is MUCH easier to do, plus, with the ability to sign-in and save your own maps, you can put detailed information related to your map location!
Read on though if you are still curious on how to embed Google Maps into Drupal with PHP!
I maintain a site for an individual who has a physical store location. I decided one day back in May 2007 to put the Google Maps API onto his site, so I set it up complete with lat/long coordinates and a marker with his address. It worked fine in FireFox and I didn't look back. Until July 2007...
I moved the core of Drupal from /index to / and in the process of making sure everything worked, I realized I needed to change the API key for the Google map. (I don't exactly know why, It just told me I needed to change it...) No big deal, I just registered for the new key, plugged it in and submitted the node page.
Well, apparently, back in May, I forgot to verify that it worked in IE, because it decided not to work after the move... I then tested IE6 to no avail... I spent about 30 min. searching Google before running across a Google Groups article that basically said 'IE' doesn't like more than than one
<body> tag. Well, I had just used the recommended Google code specified for an html page:
<body onload="load()" onunload="GUnload()"> <div id="map" style="width: 400px; height: 300px"></div> </body>
(Drupal outputs it's own
<body> tag through the template, so using the default Google code, added an additional
<body> tag. Firefox and the other compliant browsers just ignore it, but IE gets all confused, throws a fit and just doesn't display the map. Typical MS stuff...)
Initially, back in May, I toyed with the Drupal Gmap Module, but I decided not to use it because it seemed a bit bulky and confusing. I spent more time trying to get that to work, than I did copying and pasting the code...
This go-around, I decided I would just see if I could create some sort of php code to push the 'onload' function to the
<body> tag. Not knowing anything about php coding, this turned out to be a chore... I ran across and tried to implement: Phoogle Maps and GMapEZ, but these turned out to take more time to figure out than I wanted to spend time with. I did some more snooping (about 2.5 hrs worth, after trying different bits of code people suggested) and finally found a small snippet on this Drupal comment that I felt might work. I plugged the old code in along with the new and much to my surprise, a Google Map showed up! It even worked in both Firefox and IE7! (and IE6, but who uses 6? :p Ok, fine... about half of my website clients still do...) I immediately decided to blog my findings in hopes that it helps someone else out there who doesn't code, but is usually able to tinker with other's code to make it work.
In summary, this code might be used for the following situations:
(Note: I do not guarantee this code will work for you in your setting, I hope it helps though)
If you are using Drupal, be sure to set your node 'Input Format' to 'PHP Code'. You should be able to copy the following code, add your API and change the code to reflect what you want it to do. (Click here for an example of the following code)
You can also find a live site example at protruckautoandequipmentsales.com
Note: The following code is for Drupal 6. For Drupal 7, change:
drupal_set_html_head -> drupal_add_html_head