Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions /

adding google maps to page template


Reply


3 Posts   2351 Views

Avatar
spierala

Community Member, 80 Posts

20 November 2009 at 7:28am

Hello folks,

I´m new to silverstripe and I can´t find a way to make google maps run in my Page Template. I tried the jquery code found on this site: http://marcgrabanski.com/article/jquery-google-maps-tutorial-basics

The code runs perfect in a single html file I created for testing. But in silverstripe FireFox reports an JS error like this:

Error: google.maps is undefined

It seems like the source for googlemaps is not visible to my site. Actually I´m not sure where to place the link to the google js. I always placed my js files that i need in the whole application in Page.php like this:

Requirements::javascript("http://www.google.com/jsapi?key=KEYHERE");

That worked for all the other files, but fails for google. Is there a special way to include external js files?

Thanks very much for your help,
Florian

Avatar
spierala

Community Member, 80 Posts

20 November 2009 at 7:48am

Edited: 20/11/2009 7:51am

ah here more Info: thats my code in my js file:

google.load("maps", "2.x");
google.load("jquery", "1.3.1");

function initGoogle(){   
var map = new GMap2(document.getElementById('map'));
var burnsvilleMN = new GLatLng(44.797916,-93.278046);
map.setCenter(burnsvilleMN, 8);
}

and in Page.php i have this to embed the google js and jquery:

Requirements::javascript("http://www.google.com/jsapi?key=KEYHERE");
Requirements::javascript("http://code.jquery.com/jquery-latest.js");

The JS Error that my browser shows at the moment is:

GMap2 is not defined

So it seems my site finds google js source... but just does not know what GMap2 is.

Greetz,
Florian

Avatar
spierala

Community Member, 80 Posts

20 November 2009 at 8:10am

this post solved my problem. after I saw that in IE googlemaps appears... the problem must have been something else:

http://www.silverstripe.org/archive/show/1449

nice forum!

thanks,
florian