我在使用这个 google maps javascript 代码时遇到了麻烦。我想返回在谷歌地图上生成的圆的半径。Google API 提供了代码,但我不知道把它放在哪里。我到处都试过了。这是下面的代码。我做错什么了?
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0px; padding: 0px }
#map_canvas { height: 50% }
</style>
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?key=mykey&sensor=false&libraries=drawing">
</script>
<script>
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(33.65, -84.42),
zoom: 7,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map_canvas'),
mapOptions);
var drawingManager = new google.maps.drawing.DrawingManager({
drawingMode: google.maps.drawing.OverlayType.MARKER,
drawingControl: true,
drawingControlOptions: {
position: google.maps.ControlPosition.TOP_CENTER,
drawingModes: [
google.maps.drawing.OverlayType.CIRCLE
]
},
circleOptions: {
fillColor: '#01939A',
fillOpacity: .4,
strokeWeight: 5,
clickable: false,
editable: true,
zIndex: 1
}
});
drawingManager.setMap(map);
}
google.maps.event.addDomListener(window, 'load',
initialize).addListener(drawingManager, 'circlecomplete', function(circle)
{
var radius = circle.getRadius();
});
</script>
</head>
<body>
<script type="text/javascript" >
alert(radius);
</script>
<div id="map_canvas"></div>
</body>
</html>