5098 Posts in 1518 Topics by 1115 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 183 Views |
-
SS3: Using google geocoder in CMS

10 September 2012 at 2:26pm Last edited: 10 September 2012 2:59pm
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:
jQuery.noConflict();
(function($) {
$(document).ready(function() {
Behaviour.register({
'#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;
alert(address);
var request = {
address: address
};
geocoder.geocode(request, function(results, status) {
var coords = results[0].geometry.location;
console.log(coords);
$('#Form_ItemEditForm_Lat').val(coords.Xa);
$('#Form_ItemEditForm_Lng').val(coords.Ya);
});
}
} // #Form_EditForm
});
});
}(jQuery));Edit: Ahh, so behaviour.js has been removed for SS3. What might I be able to use in place of Behaviour?
| 183 Views | ||
|
Page:
1
|
Go to Top |

