2013-04-15 11 views
7

私はGoogleマップで道案内をするためにJavaScriptを少し使いましたが、何らかの理由でGoogleマップページにリダイレクトされています。Google maps directions API map.google.comにリダイレクト

問題は公共交通機関のオプションでも発生しますが、主に徒歩の方向を取得しようとするときです。

これはPhoneGapの問題ではありませんが、これはPhoneGap内で動作するアプリケーションです。

誰もこの問題を以前に見たことがありますか?

// 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]); }); 
     } 

    }); 

} 

答えて

4

私は完全に理解することはできませんよ、しかし、あなたは間違った方法を使用している可能性がある「app.directionDisplay.setMap」。

私はコードを通過しました。

私はあなたがを持っている場所を見つけることができませんでしたが MAPを初期化し、その後、あなたがルート/方向を初期化することができます別の関数を使用して、その後MAP

 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')); 

で始まるあなたのコードと疑問を持っているより多くの詳細と例GOOGLE Documentation

のために参照してください。..

私はこれは私が解決

+0

を行うことを願っていますこれは数時間前に投稿されましたが、正しいものでした。グローバル変数app.mapでマップを初期化し、document.getElementById( 'map')の代わりにそのマップを使用して問題を解決しました – gazzwi86