Skip to content

Instantly share code, notes, and snippets.

@aguimaraes
Created August 12, 2013 13:46
Show Gist options
  • Select an option

  • Save aguimaraes/6210944 to your computer and use it in GitHub Desktop.

Select an option

Save aguimaraes/6210944 to your computer and use it in GitHub Desktop.
function initialize() {
var geocoder = new google.maps.Geocoder();
var mapOptions = {
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var center = null;
if (geocoder instanceof google.maps.Geocoder) {
geocoder.geocode(
{address: 'Oxford, United Kingdom'},
function(results, status) {
var result = results[0];
if (status === 'OK') {
center = result.geometry.location;
if (center instanceof google.maps.LatLng) {
mapOptions.center = center;
}
}
var map = renderize(mapOptions);
new google.maps.Marker({position: center, map: map});
}
);
} else {
renderize(mapOptions);
}
}
function renderize(mapOptions) {
return new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
}
function loadScript() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&callback=initialize';
document.body.appendChild(script);
}
window.onload = loadScript;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment