Google maps api 3 google maps V3多段线圆绘图,错误:构造函数参数0的值无效
我正在创建一个地图,允许用户输入一个邮政编码,并在其周围绘制一个半径。我对google.maps.Polyline有问题。我收到的错误消息是“构造函数参数0的值无效”Google maps api 3 google maps V3多段线圆绘图,错误:构造函数参数0的值无效,google-maps-api-3,polyline,Google Maps Api 3,Polyline,我正在创建一个地图,允许用户输入一个邮政编码,并在其周围绘制一个半径。我对google.maps.Polyline有问题。我收到的错误消息是“构造函数参数0的值无效” <!DOCTYPE html> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <style type="text/css"> h
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0px; padding: 0px }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false">
</script>
</script>
<script type= "text/javascript">
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
}
function codeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
}
else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
function drawCircle() {
var address=document.getElementById("address").value;
var radius=document.getElementById("radius").value;
var latitude=40;
var longitude=0;
geocoder.geocode( { 'address': address}, function(results, status){
if (status==google.maps.GeocoderStatus.OK){
latlng=(results[0].geometry.location);
latitude=latlng.lat();
longitude=latlng.lng();
alert(latitude);
alert(longitude);
alert (radius);
}
else{
alert("Geocode was not successful for the following reason: " + status);
}
});
//Degrees to radians
var d2r = Math.PI / 180;
alert("calc d2r " + d2r);
// Radians to degrees
var r2d = 180 / Math.PI;
alert("calc r2d " + r2d);
// Earth radius is 3,963 miles
var cLat = (radius / 3963) * r2d;
alert("calc cLat " + cLat);
var cLng = cLat / Math.cos(latitude * d2r);
alert("calc cLng " + cLng);
//Store points in array
var points = [];
alert("declare array ");
// Calculate the points
// Work around 360 points on circle
for (var i=0; i < 360; i++) {
var theta = Math.PI * (i/16);
// Calculate next X point
circleX = longitude + (cLng * Math.cos(theta));
// Calculate next Y point
circleY = latitude + (cLat * Math.sin(theta));
// Add point to array
points.push(new google.maps.Point(circleX, circleY));
};
alert("completed loop");
var Polyline_Path = new google.maps.Polyline({
path: points,
strokeColor: "#003F87",
// color of the outline of the polyline
strokeOpacity: 1,
// between 0.0 and 1.0
strokeWeight: 5
// The stroke width in pixels
});
Polyline_Path.setMap(map);
//Add points to map
//var sColor="#003F87";
//alert("color");
//var stroke=.5;
//alert("stroke");
//map.addOverlay(new GPolyline(points, sColor, stroke));
//alert("added points to map");
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width:500px; height:460px;
-moz-outline-radius:20px; -moz-box-sizing:padding-box; -moz-outline-style:solid ;-moz-outline-color:#9FB6CD;
-moz-outline-width:10px;"></div>
<div>
Zip Code: <input id="address" type="textbox" value="">
Radius:<input id="radius" type="textbox" value="">
<input type="button" value="Find" onclick="codeAddress() ">
<input type="button" value="Draw Radius" onclick= "drawCircle() ">
</div>
</body>
</html>
html{高度:100%}
正文{高度:100%;边距:0px;填充:0px}
#地图画布{高度:100%}
var地理编码器;
var映射;
函数初始化(){
geocoder=新的google.maps.geocoder();
var latlng=新的google.maps.latlng(-34.397150.644);
变量myOptions={
缩放:8,
中心:拉特林,
mapTypeId:google.maps.mapTypeId.ROADMAP
}
map=new google.maps.map(document.getElementById(“map_canvas”),myOptions);
}
函数codeAddress(){
var address=document.getElementById(“地址”).value;
geocoder.geocode({'address':address},函数(结果,状态){
如果(status==google.maps.GeocoderStatus.OK){
map.setCenter(结果[0].geometry.location);
var marker=new google.maps.marker({
地图:地图,
位置:结果[0]。几何体。位置
});
}
否则{
警报(“地理编码因以下原因未成功:“+状态”);
}
});
}
函数drawCircle(){
var address=document.getElementById(“地址”).value;
var radius=document.getElementById(“radius”).value;
纬度=40;
var经度=0;
geocoder.geocode({'address':address},函数(结果,状态){
if(status==google.maps.GeocoderStatus.OK){
latlng=(结果[0]。几何体。位置);
纬度=latlng.lat();
经度=latlng.lng();
警报(纬度);
警报(经度);
警报(半径);
}
否则{
警报(“地理编码因以下原因未成功:“+状态”);
}
});
//度到弧度
var d2r=Math.PI/180;
警报(“计算d2r”+d2r);
//弧度
var r2d=180/Math.PI;
警报(“计算r2d”+r2d);
//地球半径为3963英里
var cLat=(半径/3963)*r2d;
警报(“calc cLat”+cLat);
var cLng=cLat/Math.cos(纬度*d2r);
警报(“计算cLng”+cLng);
//在数组中存储点
var点=[];
警报(“声明数组”);
//计算积分
//围绕圆上的360点工作
对于(变量i=0;i<360;i++){
varθ=数学PI*(i/16);
//计算下一个X点
circleX=经度+(cLng*Math.cos(θ));
//计算下一个Y点
圆圈=纬度+(克拉特*数学正弦(θ));
//将点添加到阵列
points.push(新的google.maps.Point(circleX,circleY));
};
警报(“完成循环”);
var Polyline_Path=新建google.maps.Polyline({
路径:点,
strokeColor:#003F87“,
//多段线轮廓的颜色
频闪不透明度:1,
//介于0.0和1.0之间
冲程重量:5
//笔划宽度(以像素为单位)
});
多段线路径设置图(map);
//向地图添加点
//var sColor=“#003F87”;
//警惕(“颜色”);
//var-stroke=.5;
//警惕(“中风”);
//map.addOverlay(新的GPolyline(点、颜色、笔划));
//警报(“向地图添加点”);
}
邮政编码:
半径:
您正试图使用路径
属性的点
对象数组创建多段线
(作为变量多段线
)。但是,路径
属性必须是LatLng
对象数组