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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

Simple Google Maps


Go to End


12 Posts   7993 Views

Avatar
potion_maker

Community Member, 36 Posts

13 August 2008 at 11:09am

Can someone give me an example of a simple google maps api implementation. I don't need the forum (as in the maps module) and I'm having a hard time placing the map code where i think it needs to go. Basically i'm trying to create a MapPage.ss and MapPage.php. Any help would be greatly appreciated.

Avatar
Hamish

Community Member, 712 Posts

13 August 2008 at 9:02pm

Google Maps are mostly driven by the Google Maps Javascript API.

Have a look at the API (http://code.google.com/apis/maps/).

From there, it really is just a matter of creating a page/template just like any other.

For example, say you had a MapPage and it has a db string field 'address', then you'd just use the $address variable in the javascript in the template (instead of displaying it as text).

Avatar
spenniec

Community Member, 37 Posts

14 August 2008 at 9:44pm

Edited: 14/08/2008 9:46pm

Hi
I created the attached Page type (put it in mysite/code, flush DB, create page, fill out options) and then use it by putting the following in your GMapPage.ss template.

$GetGoogleMapsScript
<div id="Map" style="width: 300px; height: 300px;"></div>

(Alternatively move the GetGoogleMapScript function to Page.php in the Controller and use it in any page...)

p.s. Looking back over it I don't think you have to do anything else, hope it works for you.

Spence

Avatar
potion_maker

Community Member, 36 Posts

24 August 2008 at 9:45am

Sorry Spence,
Where is the attached page? I appreciate the help
-J

Avatar
spenniec

Community Member, 37 Posts

24 August 2008 at 10:09pm

Sorry, thought I uploaded...

Avatar
potion_maker

Community Member, 36 Posts

27 August 2008 at 5:02am

Spence,
Thanks so much for your help. I haven't got the map to show up, but I'm not sure what exactly I should be putting in under the GoogleMapsScriptUrl section of the silverstripe cms. Can you give me an example of what would go here. Thanks again
-J

Avatar
spenniec

Community Member, 37 Posts

29 August 2008 at 3:22pm

Hi
You need to sign up for an API key
http://code.google.com/apis/maps/signup.html
Enter your site url at the bottom of the page, accept the terms and conditions and generate API key.

You will then be shown your key
eg - ABQIAAAALjOUF71zszfsH7m-f6NwYxTpgM_qsiLE9l9CVu5LVJ0VE2O9-xRDqXvdgo4m0hZyMFoArTsj6HZ3gw
Enter this in the CMS

In the example web page html you will see the script tag which has a src attribute like this src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAALjOUF71zszfsH7m-f6NwYxTpgM_qsiLE9l9CVu5LVJ0VE2O9-xRDqXvdgo4m0hZyMFoArTsj6HZ3gw"
The script URL I set up in the CMS is the url in this src attribute, minus the key
eg - http://maps.google.com/maps?file=api&amp;v=2&amp;key=
Put that value in the CMS. I included this in the CMS so that it wasn't hard coded in the class file and in case it changes.
There is a simple example of it here http://www.mccauleys.co.nz/

Avatar
potion_maker

Community Member, 36 Posts

30 August 2008 at 6:39am

Speniec,
I'm not sure why I can't get a map to show up. I've included a couple pics of what my CMS looks like with the info plugged in. My GMapPage.ss looks like this:

<div class="typography">
<h2>$Title</h2>
$Content
$GetGoogleMapsScript
<div id="Map" style="width: 300px; height: 300px;"></div>
</div>

When I look at the source code it has the google map code compiled so I'm not sure where I'm going wrong. If you want to see that go to http://www.jazzat5.org/silverstripe/location/

Thanks again. I really appreciate your time and help.

Go to Top