我正在使用 Jquery getJson() 生成要显示在 google maps 3 api 上的 json。我想按照以下示例显示折线: 折线简单示例
function initialize() {
var myLatLng = new google.maps.LatLng(0, -180);
var myOptions = {
zoom: 3,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.TERRAIN
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var flightPlanCoordinates = [
new google.maps.LatLng(37.772323, -122.214897),
new google.maps.LatLng(21.291982, -157.821856),
new google.maps.LatLng(-18.142599, 178.431),
new google.maps.LatLng(-27.46758, 153.027892)
];
var flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(map);
}
查询:
$.getJSON("routefinder", { "lat1": lat1 , "lng1": lng1 , "lat2": lat2 , "lng2": lng2 }, function(json) {
var poly = new google.maps.Polyline({
path: json,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2
});
poly.setMap(map);
});
$.getJSON 以 [new google.maps.LatLng (lat, lng) ] 格式返回带有折线坐标的字符串:
[ new google.maps.LatLng(53.369567, -6.323699), new google.maps.LatLng(53.367705, -6.317386),new google.maps.LatLng(53.337705,-6.917386), new google.maps.LatLng(53.397705,-6.47386)]
但是没有生成任何行,我可以返回一个包含 google.maps.LatLng 对象的 json 数组吗?或者显示折线的最佳方法是什么。