【发布时间】:2015-01-08 18:53:54
【问题描述】:
我正在使用 Bing 地图 ajax 控件。在我的代码中,我有以下内容 -
function getMap()
{
map = new Microsoft.Maps.Map(document.getElementById('mnMap'), {
credentials: 'MyKey',
mapTypeId: Microsoft.Maps.MapTypeId.road
});
map.setView({
zoom: 4,
center: new Microsoft.Maps.Location(defaultLat, defaultLan)
});
Microsoft.Maps.loadModule('Microsoft.Maps.Directions', {
callback: createDirectionsManager
});
}
function createDirectionsManager()
{
if (!directionsManager)
{
directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map);
}
directionsManager.resetDirections();
directionsManager.setRenderOptions({ itineraryContainer: document.getElementById('directionsPanel') });
directionsErrorEventObj = Microsoft.Maps.Events.addHandler(directionsManager, 'directionsError', displayRouteError );
directionsUpdatedEventObj = Microsoft.Maps.Events.addHandler(directionsManager, 'directionsUpdated', displayUpdatedRoute );
}
function displayUpdatedRoute(status){
// update waypoint text inputs based on dragged markers
var legs = directionsManager.getAllWaypoints();
// Do some validation
}
function displayRouteError(error){
// If the error is a viapoint error, display an error
if (error.responseCode == Microsoft.Maps.Directions.RouteResponseCode.noSolution){
directionsManager.resetDirections();
}else if (error.responseCode == Microsoft.Maps.Directions.RouteResponseCode.dataSourceNotFound || error.responseCode == Microsoft.Maps.Directions.RouteResponseCode.tooFar){
directionsManager.resetDirections();
}else{
directionsManager.resetDirections();
}
}
function getDirections(submit, send) {
directionsManager.resetDirections();
if (some test condition) {
start = new Microsoft.Maps.Directions.Waypoint({ location: new Microsoft.Maps.Location(locInputs.first().attr("data-lat"), locInputs.first().attr("data-lng")) });
} else {
start = new Microsoft.Maps.Directions.Waypoint({ address: locInputs.first().val() });
}
directionsManager.addWaypoint(start); // waypoint values come from UI based on user input string address
directionsManager.addWaypoint(waypoint);
directionsManager.addWaypoint(end);
directionsManager.setRenderOptions({ itineraryContainer: document.getElementById('directionsPanel') });
directionsManager.calculateDirections();
}
function saveTrip(){
var legs = directionsManager.getAllWaypoints();
// do some validations
//ajax call to backend
}
$("#saveTripBtn").click(function() {
getDirections();
saveTrip();
}
getMap() 已正确初始化,我可以看到正确显示的方向。在方向管理器返回的航点中。在调用后端代码之前,我需要的是 savetrip() 方法中每个航点的纬度/经度,我没有看到。
我现在使用的是开发者密钥。让我知道是否需要提供更多信息。
提前致谢
肉山
【问题讨论】:
-
只是想添加-如果我通过地址查询 SearchManager 类-我确实得到了纬度/经度
标签: javascript bing-maps driving-directions