我希望能够从坐标数组中绘制多边形线。 然而,当使用下面的代码时,它只会绘制一个点而不是一条线到数组中的每个lat / lng。 我该怎么做才能从每个纬度/ lng画一条线来形成一条线? 代码:
var poly = new Array();
for (var j = 0; j<p.Cot.length; j++) {
var pos = new google.maps.LatLng(p.Cot[0],p.Cot[1])
poly.push(pos);
}
var Path = new google.maps.Polyline({
path: poly,
geodesic: true,
strokeColor: '#ff004c',
strokeOpacity: 1.0,
strokeWeight: 5
});
Path.setMap(Map);
阵列: (第一个对象是lat,第二个是lng,第三个是标题,第四个是高度)。
婴儿床&#34;:33.091415,-112.142067,NULL,NULL,33.09549,-112.142998,25.0,1500.0,33.095802,-112.143333,320.0,2000.0,33.097103,-112.145912,320.0,2000.0,33.097431,-112.147766, 290.0,2000.0,33.097523,-112.149841,275.0,2000.0,33.097595,-112.152176,275.0,2000.0,33.097618,-112.152527,270.0,2000.0,33.097801,-112.158356,270.0,2000.0]},
答案 0 :(得分:0)
你的&#34;积分&#34;是数组中的4个数字的集合。通过数组增加4,Single.just(getInstance(context).initData())
.subscribeOn(Schedulers.io())
.subscribe(result -> {
if(result)
System.out.println("Init successful");
else
System.out.println("Init unsuccessful");
}, error -> {
System.out.println("Error occurred: " + error);
});
是纬度,index+0
是经度。
index+1
代码段
var poly = [];
for (var j = 0; j < p.Cot.length; j+=4) {
var pos = new google.maps.LatLng(p.Cot[j], p.Cot[j+1])
poly.push(pos);
}
var Path = new google.maps.Polyline({
path: poly,
geodesic: true,
strokeColor: '#ff004c',
strokeOpacity: 1.0,
strokeWeight: 5
});
Path.setMap(Map);
&#13;
function initialize() {
var Map = new google.maps.Map(
document.getElementById("map_canvas"), {
center: new google.maps.LatLng(33.091415, -112.142067),
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var poly = [];
for (var j = 0; j < p.Cot.length; j += 4) {
var pos = new google.maps.LatLng(p.Cot[j], p.Cot[j + 1])
poly.push(pos);
}
var Path = new google.maps.Polyline({
path: poly,
geodesic: true,
strokeColor: '#ff004c',
strokeOpacity: 1.0,
strokeWeight: 5
});
Path.setMap(Map);
}
google.maps.event.addDomListener(window, "load", initialize);
var p = {
Cot: [33.091415, -112.142067, null, null, 33.09549, -112.142998, 25.0, 1500.0, 33.095802, -112.143333, 320.0, 2000.0, 33.097103, -112.145912, 320.0, 2000.0, 33.097431, -112.147766, 290.0, 2000.0, 33.097523, -112.149841, 275.0, 2000.0, 33.097595, -112.152176, 275.0, 2000.0, 33.097618, -112.152527, 270.0, 2000.0, 33.097801, -112.158356, 270.0, 2000.0]
};
&#13;
html,
body,
#map_canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
&#13;