Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Customising the CMS /

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

SS3: Using google geocoder in CMS

Go to End



Community Member, 2 Posts

10 September 2012 at 2:26pm

Edited: 10/09/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 :D

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?