Created
May 11, 2015 15:11
-
-
Save cjjavellana/43afec8962e337a79cc4 to your computer and use it in GitHub Desktop.
Loading map in rails
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
<script type="text/javascript"> | |
function initialize() { | |
//var mapOptions = { | |
// zoom: 4, | |
// center: new google.maps.LatLng(-34.397, 150.644) | |
//}; | |
//var map = new google.maps.Map(document.getElementById('geolocation'), | |
// mapOptions); | |
var handler = Gmaps.build('Google'); | |
handler.buildMap({ provider: {zoom: 17}, internal: {id: 'geolocation'}}, function(){ | |
if(navigator.geolocation) | |
navigator.geolocation.getCurrentPosition(displayOnMap); | |
}); | |
function displayOnMap(position){ | |
var marker = handler.addMarker({ | |
lat: position.coords.latitude, | |
lng: position.coords.longitude | |
}); | |
handler.map.centerOn(marker); | |
}; | |
} | |
$(document).ready(function(){ | |
var script = document.createElement('script'); | |
script.type = 'text/javascript'; | |
script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp' + | |
'&key=AIzaSyAbFH5JHChuqLwHNad_ypoJZCqd49kP6Lw&callback=initialize'; | |
document.body.appendChild(script); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment