我可以使用 cloudmade api 很好地检索方向,但我似乎无法将这些坐标添加到我的地图中。
我尝试了两种不同的方法
var myStyle = {
"color": "#ff7800",
"weight": 5,
"opacity": 0.65
};
var myLines = [{
"type": "LineString",
"coordinates": []
}];
myLines.coordinates = [[]];
for (var i = result.data.route_geometry.length - 1; i >= 0; i--) {
if(!isNaN(result.data.route_geometry[i][0]) && !isNaN(result.data.route_geometry[i][1])){
myLines.coordinates[i] = [result.data.route_geometry[i][0], result.data.route_geometry[i][1]];
}
};
L.geoJson(myLines, {style: myStyle}).addTo(window.map);
和
var geojsonFeature = {
"type": "Feature",
"properties": {
"name": "Coors Field",
"amenity": "Baseball Stadium",
"popupContent": "This is where the Rockies play!"
},
"geometry": {
"type": "Point",
"coordinates": []
}
};
for (var i = result.data.route_geometry.length - 1; i >= 0; i--) {
if(!isNaN(result.data.route_geometry[i][0]) && !isNaN(result.data.route_geometry[i][1])){
geojsonFeature.geometry.coordinates[i] = [result.data.route_geometry[i][0], result.data.route_geometry[i][1]];
}
};
L.geoJson(geojsonFeature).addTo(window.map);
我可以很好地添加标记。我的问题类似于这个Leaflet GeoJSON display,所以我尝试像这样反转坐标
myLines.coordinates[i] = [result.data.route_geometry[i][0], result.data.route_geometry[i][1]];
但我仍然没有在地图上添加任何内容。
控制台中没有错误。