Google map API - Første og sidste Annotation
HejJeg henter min "makører" i en xml fil.
Jeg ønsker kun at få den første og sidste vist på kortet - samtidig ønsker jeg at vise min polyline (flightpath2) mellem alle makører.
Følgende script viser kun min første makør og ingen polyline.
for (var i = 0; i < markers.length; i++) {
console.log(markers.length);
flightPlanCoordinates[i] = new google.maps.LatLng(markers[i].getAttribute("lat"), markers[i].getAttribute("lng"));
console.log(flightPlanCoordinates[i]);
var name = markers[i].getAttribute("name");
var address = markers[i].getAttribute("address");
var type = markers[i].getAttribute("BalloonStatus");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var html = "<b>" + name + "</b> <br/>" + address;
var icon = customIcons[type] || {};
if ((i = 0) || (i=markers.length-1)) {
console.log("Marker made");
var marker = new google.maps.Marker({
map: map,
position: point,
icon: icon.icon,
shadow: icon.shadow
});
gmarkers.push(marker);
bindInfoWindow(marker, map, infoWindow, html);
lastlat = markers[i].getAttribute("lat");
lastlng = markers[i].getAttribute("lng");
}
}
flightPath2 = new google.maps.Polyline({
path: flightPlanCoordinates,
strokeColor: "#0000FF",
strokeOpacity: 0.8,
strokeWeight: 2
});
console.log(flightPath2)
flightPath2.setMap(map);
Sjovt nok, så viser dette script min polyline og alle min makører - hvad overser jeg ?
for (var i = 0; i < markers.length; i++) {
flightPlanCoordinates[i] = new google.maps.LatLng(markers[i].getAttribute("lat"), markers[i].getAttribute("lng"));
console.log(flightPlanCoordinates[i]);
var name = markers[i].getAttribute("name");
var address = markers[i].getAttribute("address");
var type = markers[i].getAttribute("BalloonStatus");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var html = "<b>" + name + "</b> <br/>" + address;
var icon = customIcons[type] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
icon: icon.icon,
shadow: icon.shadow
});
gmarkers.push(marker);
bindInfoWindow(marker, map, infoWindow, html);
lastlat = markers[i].getAttribute("lat");
lastlng = markers[i].getAttribute("lng");
}
flightPath2 = new google.maps.Polyline({
path: flightPlanCoordinates,
strokeColor: "#0000FF",
strokeOpacity: 0.8,
strokeWeight: 2
});
console.log(flightPath2)
flightPath2.setMap(map);