Skip to content

Instantly share code, notes, and snippets.

@webapprentice
Last active December 27, 2015 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webapprentice/7379636 to your computer and use it in GitHub Desktop.
Save webapprentice/7379636 to your computer and use it in GitHub Desktop.
Display a Google Map using the Maps JavaScript API
<style>
#map_canvas {
height: 400px;
width: 600px;
border: 1px solid black;
}
</style>
<div id="map_canvas"></div>
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY_GOES_HERE&sensor=false"></script>
<script>
function initialize() {
var myLocation = {
'latitude': 48.858574,
'longitude': 2.294508,
'address': 'Eiffel Tower, Paris'
};
var myLatlng = new google.maps.LatLng( myLocation.latitude, myLocation.longitude );
var mapOptions = {
zoom: 16,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
}
var map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: myLocation.address
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment