1
我正在升級到Google地圖的第3版,並且在加載我的多段線時遇到了一些麻煩。我已將我的代碼從此鏈接中提供的答案中刪除:draw path using polylines from a xml file,其中有幾個變體用於匹配我的XML文件。使用XML文件在Google Maps 3中創建多段線
downloadUrl("byway.xml", function(doc) {
var xmlDoc = xmlParse(doc);
var trks = xmlDoc.documentElement.getElementsByTagName("trk");
var bywaypath = [];
for (var i = 0; i < trks.length; i++) {
var trkPoints = trks[i].getElementsByTagName("trkpt");
for (var j = 0; j<trkPoints.length; j++) {
var lat = parseFloat(trkPoints[j].getAttribute("lat"));
var lng = parseFloat(trkPoints[j].getAttribute("lng"));
var point = new google.maps.LatLng(lat,lng);
bywaypath.push(point);
}
}
var myPath = new google.maps.Polyline({
path: bywaypath,
strokeColor: "#008eb0",
strokeOpacity: 1.0,
strokeWeight: 3
});
myPath.setMap(map); });
這裏是我的XML文件的樣子:
<gpx version="1.1" creator="RouteBuddy" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/1" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
<wpt lat="30.23041000" lon="-88.02368200">
<ele>935.481445</ele>
<trk>
<name>ACC</name>
<trkseg>
<trkpt lat=" 30.23047759 " lon=" -88.02365995 "></trkpt>
<trkpt lat=" 30.23040677 " lon=" -88.02368044 "></trkpt>
<trkpt lat=" 30.23041 " lon=" -88.023682 "></trkpt>
<trkpt lat=" 30.230062 " lon=" -88.023445 "></trkpt>
<trkpt lat=" 30.229971 " lon=" -88.023339 "></trkpt>
<trkpt lat=" 30.229628 " lon=" -88.022956 "></trkpt>
<trkpt lat=" 30.229628 " lon=" -88.022956 "></trkpt>
<trkpt lat=" 30.22975762 " lon=" -88.02288814 "></trkpt>
<trkpt lat=" 30.22973402 " lon=" -88.02284032 "></trkpt>
<trkpt lat=" 30.22973402 " lon=" -88.02284032 "></trkpt>
在我做錯了任何想法?提前致謝!
嗯,我很尷尬,你必須幫我但是非常感謝你看到了這個簡單的錯誤,我改變了它,現在所有的工作都已經開始了,謝謝!!! – jmtmay
順便說一下,感謝你在Google地圖上的所有例子,他們幫助我在幾個項目中! – jmtmay
如果答案對你有效,請[接受](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)。 – geocodezip