Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Simple Google Maps

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

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

Page: 1 2
Go to End
Author Topic: 5751 Views
  • potion_maker
    Avatar
    Community Member
    36 Posts

    Simple Google Maps Link to this post

    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.

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Simple Google Maps Link to this post

    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).

  • spenniec
    Avatar
    Community Member
    37 Posts

    Re: Simple Google Maps Link to this post

    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

  • potion_maker
    Avatar
    Community Member
    36 Posts

    Re: Simple Google Maps Link to this post

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

  • spenniec
    Avatar
    Community Member
    37 Posts

    Re: Simple Google Maps Link to this post

    Sorry, thought I uploaded...

  • potion_maker
    Avatar
    Community Member
    36 Posts

    Re: Simple Google Maps Link to this post

    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

  • spenniec
    Avatar
    Community Member
    37 Posts

    Re: Simple Google Maps Link to this post

    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/

  • potion_maker
    Avatar
    Community Member
    36 Posts

    Re: Simple Google Maps Link to this post

    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.

    5751 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.