Search

Hey everyone. I came up with this XSL utility, Get Google Map, that allows you to easily add a Google Map(s) to your site. Hopefully, this will be a great help to some folks. Please let me know if there is a better way I can do this.

UPDATED - October 14, 2009 7:15 PM CST

Version 1.3

Changes from 1.2: Changes: Need API Key for Geocode support. This changed when Google added their language support in v3

Changes from 1.1: Added the parameter map-id – this will allow you to include multiple maps

Changes from 1.0: Now built for Google Maps API v3; Removed need for API Key; Added parameters map-type (ROADMAP, SATELLITE, HYBRID, or TERRAIN) and zoom-level

Nice work! Although, shouldn’t it be possible to include the two scripts in the utility as well so that the user only has to pass the API key as another parameter?

Also, would you mind helping me improve the Map Location Field extension? Code contributions and ideas, suggestions or tips for an improved cooperation with your util are equally appreciated. :-)

@phoque - Thanks!

I’d be happy to help improve the Map Location Field extension. Unfortunately, when comes to PHP, my skills are less than desirable. I’ll be happy to look over the extension and see if there is anything that I can contribute to.

Also, in regards to your question about the API Key, I’m sure there is a way to do that. I’ll re-look at my code and see if that is possible.

Thanks bzerangue, I have been implementing Google maps by hand for several projects. This is much better, of course.

@carsten - No problem. Glad to provide it. Please let me know if you find any way to improve it. phoque brought up some good points.

OK. I reworked the utility code. The new version of the Google Maps API (v3) does not require an API Key.

UPDATED

@phoque - look at the new code in the <head> element.

<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<script type="text/javascript" src="http://www.google.com/jsapi?autoload=%7Bmodules%3A%5B%7Bname%3A%22maps%22%2Cversion%3A3%2Cother_params%3A%22sensor%3Dfalse%22%7D%5D%7D"/>

In v3 of the Google Maps API, the javascript now doesn’t need the API key. PLUS there is an autoload feature… this might help your plugin. The autoload feature “shows how to use the autoload option of the AJAX Common Loader, which eliminates one trip to the server and can lead to faster loading sites.” I got this idea via the Google Maps demos, http://code.google.com/apis/maps/documentation/v3/demogallery.html

@phoque - look at the new code in the <head> element.

Ah, cool.

But still, <script> should be in the util as well. That way it’ll only be a template-call, not a template-call AND a <script>-element.

I think I have found a strange bug:

When the template call for the utility is made inside a div, the address(and pointer) doesnt work. it only works when ‘naked’ inside a template. (in a scenarion of nested apply templates)

edit: It was the attribute id="intro" of the div that cuased this, any other id and it works.
I do have a template with a mode named intro
It seems div attributes and template modes of the same name can clash?…

Whoah! I don’t know! Allen, can you be of some help?

@phoque: I’m not sure how Google maps work and whether or not the <script> element can be in the body or if it must be on the page <head>. If it must be in <head> then I don’t see the problem with bzerangue’s approach.

It’s possible to use template match overriding technique to make the process a little more elegant but that will require a certain level of assumption to one’s main template structure.

bzerangue’s method of using call-template requires no assumption on a implementer’s part.

@newnomad: mode and id don’t “clash”. Also, I don’t think it is at all related to this utility since this utility uses explicit calls to a named template rather than rule matching.

@phoque: I’m not sure how Google maps work and whether or not the <script> element can be in the body or if it must be on the page <head>. If it must be in <head> then I don’t see the problem with bzerangue’s approach.

It doesn’t matter, it’s allowed in both body and head.

UPDATED - August 4, 2009 1:17 AM CST

@bzerangue I think if they’d just let you work while the sun’s not up, you’d get all your work done while you’re having your creative juices going.

UPDATED

As of this morning, this utility would crash. It has a Geocoding template in there that uses the Google Geocoding service to get your latitude and longitude. Well, since Google updated to v3 of the API, we didn’t need the API to show the map on our webpage, and also I found out at the time, we didn’t need the API for the Geocoding service as well (or it was working fine without it). Well that was until October 13 when Google made changes to their library when the added language support for the maps. Well, since then it threw off my ability to generate the geocode. Well, I found out that I needed an API for the Geocoding service. So, I went ahead and added a variable in this utility where you can add your API Key to the template. I updated the utility and instructions.

Sorry for the inconvenience.

Brian,

The utility posted on the website doesn’t actually use the API Key in the geocode template (@line 139 or so), so I manually added it in. Perhaps I jumped the gun on this updated utility though :P Thanks for the utility by the way, it simplifies using a map greatly.

        <xsl:variable name="urlString">http://maps.google.com/maps/geo?q=<xsl:value-of select="$encodedAddress"/>&amp;output=xml&amp;key=...</xsl:variable>

@scottkf -

Scott, thanks so much for catching that. It’s been a long day. I typed in the changes but never updated them on the utilities page. Thank you so much for the kind words. I’m glad it’s been a help to you.

Sorry for the confusion earlier. Please let me know if I missed anything else.

Hi bzerangue,
is it possible to add multiple pointers to the same map?

Thanks!!

@Manaus, it is Manaus, but not with the XSLT Utility as it is currently written. That is for one location.

You might consider looking the Google Maps API on to get Multiple Markers and adjust the utility based off of that.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details