Created
October 30, 2011 05:49
-
-
Save paulkaplan/1325563 to your computer and use it in GitHub Desktop.
Google Map click generates marker and yaml with 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> | |
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> | |
<style type="text/css"> | |
html { height: 100% } | |
body { height: 100%; margin: 0; padding: 0 } | |
#map_canvas { height: 100% } | |
</style> | |
<script type="text/javascript" | |
src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> | |
<script type="text/javascript" | |
src="http://maps.googleapis.com/maps/api/js?sensor=true"> | |
</script> | |
<script type="text/javascript"> | |
function initialize() { | |
var stop = 0 | |
var latlng = new google.maps.LatLng(41.79,-87.59); | |
var myOptions = { | |
zoom: 17, | |
center: latlng, | |
mapTypeId: google.maps.MapTypeId.ROADMAP | |
}; | |
var map = new google.maps.Map(document.getElementById("map_canvas"), | |
myOptions); | |
google.maps.event.addListener(map, 'click', function(event){ | |
placeMarker(event.latLng) | |
$("#yaml").append("<pre id=stop"+stop+">-\n name: "+stop+"\n latitude: "+ event.latLng.lat() + "\n longitude: "+event.latLng.lng() + "</pre> ") | |
stop = stop + 1 | |
}); | |
var markerArray | |
function placeMarker(location) { | |
var marker = new google.maps.Marker({ | |
position: location, | |
map: map | |
}); | |
google.maps.event.addListener(marker, 'click', function(event) { | |
$("#"+(stop-1)).remove() | |
stop = stop-1 | |
marker.setMap(null) | |
}) | |
} | |
} | |
</script> | |
</head> | |
<body onload="initialize()"> | |
<div id="map_canvas" style="width:70%; height:100%; float:left;"></div> | |
<div id="yaml" style="width:25%; float:right"> | |
<end> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment