Jump to:

5540 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » SS3: Using google geocoder in CMS

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

Page: 1
Go to End
Author Topic: 342 Views
  • Elzabar
    Community Member
    2 Posts

    SS3: Using google geocoder in CMS Link to this post

    I am trying to use googles geocoder service to store the latitude and longitude of a location once it is saved in the CMS. These will then be used in the front end to place markers on the map. I've gotten it to work on page load, but I want it to happen automatically before a location is saved. I've tried using SilverStripes beforeSave function but with no luck. Help would be greatly appreciated

    Here is the JavaScript I am using in the backend:


    (function($) {
    $(document).ready(function() {
          '#Form_ItemEditForm' : {
        initialize : function() {
        this.observeMethod('PageLoaded', this.pageLoaded);
        this.observeMethod('BeforeSave', this.beforeSave);
        this.pageLoaded(); // call pageload initially too.
        pageLoaded : function() {
        alert("You loaded a page");
             beforeSave: function() {
                var geocoder = new google.maps.Geocoder();
                var country = $('#Form_ItemEditForm_Country').val();
                var city = $('#Form_ItemEditForm_City').val();
                var address = country + ', ' + city;
                var request = {
                   address: address
                geocoder.geocode(request, function(results, status) {
                   var coords = results[0].geometry.location;
        } // #Form_EditForm

    Edit: Ahh, so behaviour.js has been removed for SS3. What might I be able to use in place of Behaviour?

Page: 1
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.