Google Maps Api Drawing a Circle

匿名 (未验证) 提交于 2019-12-03 01:48:02

问题:

Hi i've a problem with Google maps api, i'am using the library Drawing and don't know if this is normal but when i am using Circle Drawing at the moment to start to draw this don't appear in the map only appear when the circle is completed, but the other controller like polygon or rectangle it's appear in the momento to start to draw, i did copy the example that google maps api have in their page and happen the same..

Some solution.. Thanks for the help.

This is code from Google maps API

<!DOCTYPE html> <html>   <head>     <title>Drawing tools</title>     <meta name="viewport" content="initial-scale=1.0, user-scalable=no">     <meta charset="utf-8">     <style>       html, body, #map-canvas {         height: 100%;         margin: 0px;         padding: 0px       }     </style>     <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=drawing"></script>     <script> function initialize() {   var mapOptions = {     center: new google.maps.LatLng(-34.397, 150.644),     zoom: 8   };    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.MARKER,         google.maps.drawing.OverlayType.CIRCLE,         google.maps.drawing.OverlayType.POLYGON,         google.maps.drawing.OverlayType.POLYLINE,         google.maps.drawing.OverlayType.RECTANGLE       ]     },     markerOptions: {       icon: 'images/beachflag.png'     },     circleOptions: {       fillColor: '#ffff00',       fillOpacity: 1,       strokeWeight: 5,       clickable: false,       editable: true,       zIndex: 1     }   });   drawingManager.setMap(map); } google.maps.event.addDomListener(window, 'load', initialize);     </script>   </head>   <body>     <div id="map-canvas"></div>   </body> </html> 

回答1:

Try this code after your map is loaded. Its working for me.

var rad=9; var draw_circle=null; draw_circle = new google.maps.Circle({                                      center: new google.maps.LatLng(32.0833, 34.8000),                                      radius: rad,                                      strokeColor: "#FFFFFF",                                      strokeOpacity: 0.8,                                      strokeWeight: 2,                                      fillColor: "#FFFFFF",                                      fillOpacity: 0.35,                                      map: map                                      }); 

Hope it helps.!



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!