Created
August 12, 2013 13:46
-
-
Save aguimaraes/6210944 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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