我正在尝试在Google地图上插入此圈子,通过在标题中包含以下js文件,地图显示正常;
/**
* Called on the intiial page load.
*/
function initialize() {
var latLng = new google.maps.LatLng(50.272213,-5.054973);
var options = {
'zoom': 9,
'center': latLng,
'mapTypeId': google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map'),
options);
}
// Register an event listener to fire when the page finishes loading.
google.maps.event.addDomListener(window, 'load', initialize);
但是,当我添加以下内容以包含圆圈时,它会断开并且不会加载;
/**
* Called on the intiial page load.
*/
function initialize() {
var latLng = new google.maps.LatLng(50.272213,-5.054973);
var options = {
'zoom': 9,
'center': latLng,
'mapTypeId': google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map'),
options);
// Add a Circle overlay to the map.
var circle = new google.maps.Circle({
map: map,
center: new google.maps.LatLng(50.272213,-5.054973),
fillColor: #00FF00,
fillOpacity: 0.2,
strokeColor: #00FF00,
strokeOpacity: 0.4,
strokeWeight: 2
});
circle.setRadius(18362.55489862987);
}
// Register an event listener to fire when the page finishes loading.
google.maps.event.addDomListener(window, 'load', initialize);
如果有人能指出我哪里出错了,请...
答案 0 :(得分:1)
不要调用setRadius,只需将radius指定为圆选项的参数即可。另外,假设您已经使用与圆心相同的坐标创建了一个latlng对象,只需重复使用即可。
var circle = new google.maps.Circle({
map: map,
center: latLng,
fillColor: #00FF00,
fillOpacity: 0.2,
strokeColor: #00FF00,
strokeOpacity: 0.4,
strokeWeight: 2,
radius: 18362.55489862987
});
答案 1 :(得分:0)
尝试将您的侦听器代码更改为:
google.maps.event.addDomListener(window, 'onload', initialize());
以下是一个工作示例:http://jsfiddle.net/pVh3b/1/