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.
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.
- Page 11(current)
- 2
- Next 10 entries
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).
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
Sorry Spence,
Where is the attached page? I appreciate the help
-J
Sorry, thought I uploaded...
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
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&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/
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.
- Page 11(current)
- 2
- Next 10 entries