Last active
December 11, 2015 13:59
-
-
Save dbburgess/4611386 to your computer and use it in GitHub Desktop.
A simple example of using the Google Maps API (v3) to place pins where the user clicks on the map, and then get the coordinates of that location. Simply hover over the marker with your mouse to see the coordinates.
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Simple Google Maps Marker Creation Example</title> | |
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"> | |
<meta charset="utf-8"> | |
<style type="text/css"> | |
html, body { | |
height: 100%; | |
margin: 0; | |
padding: 0; | |
} | |
#map_canvas { | |
height: 100%; | |
} | |
</style> | |
<script src="https://maps.googleapis.com/maps/api/js?v=3&sensor=false"></script> | |
<script> | |
function initialize() { | |
var mapOptions = { | |
zoom: 16, | |
center: new google.maps.LatLng(-34.6038, -58.3815), | |
mapTypeId: google.maps.MapTypeId.HYBRID | |
}; | |
var map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions); | |
google.maps.event.addListener(map, 'click', function(event) { | |
var marker = new google.maps.Marker({ | |
position: new google.maps.LatLng(event.latLng.lat(), event.latLng.lng()), | |
title: event.latLng.lat() + ', ' + event.latLng.lng(), | |
map: map | |
}); | |
}); | |
} | |
google.maps.event.addDomListener(window, 'load', initialize); | |
</script> | |
</head> | |
<body> | |
<div id="map_canvas"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment