I have been using the google api for this, andthere are several similar posts, but nothing relating to this. I have written implementation very similar using polygons, but this one uses draw. I am getting an error "google is not defined"
on the event listeners, and it makes no sense because the headers are the same as they are in the file that works. I am at a complete lost as why this is not showing the points as I mark them. Here is my code for the whole thing.
JSBin:This is where I am at. http://jsbin.com/woqixir/edit?html,output
This is my other snippet that I am working from on fiddle: https://jsfiddle.net/tubbstravis/864um322/ I am simply trying to do the same thing, but with draw.Instead of polygon.
<!DOCTYPE html>
<html>
<head>
<title>HireMaster: Select Location</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
width: auto;
height: 600px;
}
#info {
position: absolute;
font-family: arial, sans-serif;
font-size: 18px;
font-weight: bold;
}
</style>
</head>
<body>
<div id="map"></div>
<div id="info">
</div>
<script>
function initMap() {
center: {lat: 38, lng: 265},
zoom: 5,
mapTypeId: google.maps.MapTypeId.HYBRID
var map = new google.maps.Map(document.getElementById('map'), {
});
var drawingManager = new google.maps.drawing.DrawingManager({
drawingMode: google.maps.drawing.OverlayType.POLYGON,
drawingControl: true,
drawingControlOptions: {
position: google.maps.ControlPosition.TOP_CENTER,
drawingModes: [
]
},
markerOptions: {icon: 'https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png'},
circleOptions: {
fillColor: '#ffff00',
fillOpacity: 1,
strokeWeight: 5,
clickable: false,
editable: true,
zIndex: 1
}
});
drawingManager.setMap(map);
google.maps.event.addListener(drawingManager, "dragend", getCoords);
google.maps.event.addListener(drawingManager.getPath(), "insert_at", getCoords);
google.maps.event.addListener(drawingManager.getPath(), "remove_at", getCoords);
google.maps.event.addListener(drawingManager.getPath(), "set_at", getCoords);
}
function getCoords() {
var len = drawingManager.getPath().getLength();
var htmlStr = "";
for (var i = 0; i < len; i++) {
var counter = i + 1;
htmlStr += "Point " + counter + ": " + drawingManager.getPath().getAt(i).toUrlValue(5) + "<br>";
console.log(htmlStr);
}
document.getElementById('info').innerHTML = htmlStr;
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDzUfosWJzaDKzYuffioH8liWWmbdPzwAQ&libraries=drawing&callback=initMap"
async defer></script>
</body>
</html>