Client address Google maps widget
Code below adds Google maps widget into "view client" tab showing client location on the map based on the address entered
var address = '';
function initializeGMap() {
var elt = new Element('div', { 'style': 'position: relative; top: 0px; left: 0px; width: 350px; height: 350px;' });
$$('#pane_right')[0].appendChild(elt);
var geo = new google.maps.Geocoder();
geo.geocode( { 'address' : address, 'region' : 'GB' }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var options = { zoom: 15, center: results[0].geometry.location, mapTypeId: google.maps.MapTypeId.ROADMAP };
var map = new google.maps.Map(elt, options);
var marker = new google.maps.Marker({ map: map, position: results[0].geometry.location });
} else {
if (console) console.log("geocode failure reason: " + status);
var options = { zoom: 5, center: new google.maps.LatLng(54.577349, -4.19403), mapTypeId: google.maps.MapTypeId.ROADMAP };
var map = new google.maps.Map(elt, options);
}
});
}
Event.observe(window, 'load', function () {
if (document.URL.indexOf('viewclient.aspx' > 0)) {
var form = $('aspnetForm');
var address1 = form['ctl00$MainContent$client_formAddress1'].getValue();
if (address1 && !address1.blank()) address = address1;
var address2 = form['ctl00$MainContent$client_formAddress2'].getValue();
if (address2 && !address2.blank()) address = address + (address.blank() ? '' : ',') + address2;
var townCity = form['ctl00$MainContent$client_formTownCity'].getValue();
if (townCity && !townCity.blank()) address = address + (address.blank() ? '' : ',') + townCity;
var county = form['ctl00$MainContent$client_formCounty'].getValue();
if (county && !county.blank()) address = address + (address.blank() ? '' : ',') + county;
if (!address.blank()) {
document.body.appendChild(new Element('script', { 'type' : 'text/javascript', 'src' : 'https://maps.googleapis.com/maps/api/js?key=AIzaSyCVfbzcGbsl4VUHxXmOOGQ_2NxHFE8AQ2Q&sensor=false®ion=GB&callback=initializeGMap' }));
}
}
});
-
Hi Jon! That's because the "src" link was cut by Zendesk, try the file attached.
Also it'll be great if you could generate your own API key for Google Maps https://developers.google.com/maps/documentation/javascript/tutorial?hl=en-EN#api_key
Best
Denis
map.js
Please sign in to leave a comment.
Comments
2 comments