17488 Posts in 4473 Topics by 1978 members
| Go to End | Next > | |
| Author | Topic: | 5509 Views |
-
Simple Google Maps

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.
-
Re: Simple Google Maps

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).
-
Re: Simple Google Maps

14 August 2008 at 9:44pm Last edited: 14 August 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
-
Re: Simple Google Maps

24 August 2008 at 9:45am
Sorry Spence,
Where is the attached page? I appreciate the help
-J -
Re: Simple Google Maps

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 -
Re: Simple Google Maps

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 CMSIn 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&v=2&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&v=2&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/ -
Re: Simple Google Maps

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.
| 5509 Views | ||
| Go to Top | Next > |



