其中,searchStr ="demo.html",目标URL地址。
function navigation(searchStr, flat, flon, tlat, tlon, v, fast) {
var positions = [];
_data.positionDistance = {};
_data.positionDuration = {};
jQuery.ajax({
type : "get",
async : false,
url : searchStr,
data : {
flat : flat,
flon : flon,
tlat : tlat,
tlon : tlon,
v : v,
fast : fast,
layer : 'mapnik',
format : "geojson"
},
contentType : "application/json; charset=utf-8",
dataType : "json",
cache : false,
success : function (data) {
$.each(data.coordinates, function (i, item) {
var point = {};
point.lon = item[0];
point.lat = item[1];
positions.push(point);
});
$.each(data.properties, function (i, item) {
if (typeof item === "number") {
_data.positionDistance = new RouteDistance();
_data.positionDistance.value = item;
_data.positionDistance.unit = "km";
_data.positionDuration = new RouteDuration();
_data.positionDuration.value = calculateDuration(v, item);
}
});
},
error : function (errorCB) {
if (errorCB) {
setTimeout(function () {
errorCB(new WebAPIError(WORK_ERR));
}, 1);
}
}
});
return positions;
}
由于本来是异步的,要变成同步的,如上面所写。