admin管理员组文章数量:1391975
I am working on the below code. Why is the Drawing Manager not showing on the Map?
$(document).ready(function () {
var map;
var latlng = new google.maps.LatLng(49.241943, -122.889318);
var myOptions = {
zoom: 12,
center: latlng,
disableDefaultUI: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
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);
});
I checked the console and I get this error message:
Uncaught TypeError: Cannot read property 'DrawingManager' of undefined
I am working on the below code. Why is the Drawing Manager not showing on the Map?
$(document).ready(function () {
var map;
var latlng = new google.maps.LatLng(49.241943, -122.889318);
var myOptions = {
zoom: 12,
center: latlng,
disableDefaultUI: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
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);
});
I checked the console and I get this error message:
Share Improve this question edited Oct 29, 2023 at 21:39 halfer 20.4k19 gold badges109 silver badges202 bronze badges asked Mar 6, 2014 at 3:45 user1760110user1760110 2,3366 gold badges32 silver badges37 bronze badgesUncaught TypeError: Cannot read property 'DrawingManager' of undefined
2 Answers
Reset to default 6Ok I got the issue
I had to change the Google Map Javascript Library to
<script src="https://maps.googleapis./maps/api/js?v=3.exp&sensor=false&libraries=drawing"></script>
I met the same issue. At last, found that the problem maybe came from the confliction of google map js libraries. In my code, I'm using the
<script type="text/javascript" src="https://maps.googleapis./maps/api/js?v=3.exp&sensor=false&libraries=drawing"></script>
to load the drawing library, then in another place I'm using google jsapi to load google map library by
google.load("map", "3")
After I remove the google.load("map", "3") code, the error gone.
本文标签: javascriptDrawing Manager not showing on Google MapStack Overflow
版权声明:本文标题:javascript - Drawing Manager not showing on Google Map - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744706650a2620878.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论