Javascript 谷歌地图方向API重定向至map.Google.com
我使用了一点JavaScript在我的谷歌地图上获取方向,但出于某种原因,我一直被重定向到谷歌地图页面 问题是当我试图主要了解步行方向时,尽管公共交通选项也会出现这种情况 这是一个在PhoneGap中工作的应用程序,尽管我不确定这是否是PhoneGap的问题 以前有人看到过这个问题吗,或者有人看到我的实现有问题吗Javascript 谷歌地图方向API重定向至map.Google.com,javascript,google-maps,cordova,google-maps-api-3,Javascript,Google Maps,Cordova,Google Maps Api 3,我使用了一点JavaScript在我的谷歌地图上获取方向,但出于某种原因,我一直被重定向到谷歌地图页面 问题是当我试图主要了解步行方向时,尽管公共交通选项也会出现这种情况 这是一个在PhoneGap中工作的应用程序,尽管我不确定这是否是PhoneGap的问题 以前有人看到过这个问题吗,或者有人看到我的实现有问题吗 // get drections directions: function (method) { // set directions method metho
// get drections
directions: function (method) {
// set directions method
method = google.maps.DirectionsTravelMode.WALKING;
if (method === 'public')
method = google.maps.DirectionsTravelMode.TRANSIT;
// current position
var currentPos = new google.maps.LatLng(app.positionCords.latitude, app.positionCords.longitude);
// set the directions options
var request = {
origin: currentPos,
destination: app.venueCords,
travelMode: method
};
// get the directions
app.directionsService.route(request, function (response, status) {
if (status == google.maps.DirectionsStatus.OK) {
// set up directions on the map
app.directionsDisplay.setMap(document.getElementById('map'));
app.directionsDisplay.setPanel(document.getElementById('directionsPanel'));
app.directionsDisplay.setDirections(response);
} else {
app.messageBox.alert(app.alertTitle, app.noDirectionsMsg, function(button) { console.warn('alert', [this, arguments]); });
}
});
}
我不能完全理解,但您可能使用了错误的方法“app.directionDisplay.setMap” 因为我已经通过了代码 我无法找到您在哪里初始化地图,然后您可以为地图指定方向
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(-34.397, 150.644),//put your initial position values
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"),
mapOptions);
}
然后使用不同的功能可以初始化路线/方向
有关更多详细信息和示例,请参阅
我对你的代码有疑问
// set up directions on the map
app.directionsDisplay.setMap(document.getElementById('map'));
请改正那一点
我希望这样做我在你发布前几个小时解决了这个问题,但你是对的。我在一个全局变量app.map中初始化了映射,并使用它而不是document.getElementById('map')解决了这个问题