javascript - Sencha Touch : Can't get map object from Ext. map 提供给谷歌方向服务

标签 javascript google-maps-api-3 sencha-touch-2

我有一个 Ext.Map 对象,我试图从中获取 google.maps.map() 对象,但它没有返回有效对象,所以我无法在 map 上呈现方向。

addMaps: function(options){
    directionsDisplay =new google.maps.DirectionsRenderer();        
    directionsService = new google.maps.DirectionsService();
    activeMarkers = new Array();
    uconnPosition = new google.maps.LatLng(41.809929, -72.25486);
    myMapPosition = new google.maps.LatLng(41.809929, -72.25486);
    curBuildingPosition = new google.maps.LatLng(41.809929, -72.25486);

    uconnMap = new Ext.Map({

        mapOptions : {
            center : new google.maps.LatLng(41.809929, -72.25486),  //UConn
            zoom : 16,
            mapTypeId : google.maps.MapTypeId.ROADMAP,
            navigationControl: true,
            navigationControlOptions: {
                    style: google.maps.NavigationControlStyle.DEFAULT
                }
        },

        plugins : [
            new Ext.plugin.GMap.Tracker({
                    trackSuspended : true,   //suspend tracking initially
                    highAccuracy   : false,
                    marker : new google.maps.Marker({
                        position: uconnPosition,
                        title : 'My Current Location',
                        shadow: shadow,
                        icon  : image
                      })
            })
        ]

    });




   UConnApp.views.uconnTourMainPanel.add(uconnMap);
   directionsDisplay.setMap(uconnMap.getMap()); //THIS IS WHERE I THINK THE PROBLEM IS
   var org = new google.maps.LatLng(41.806501, -72.252769);
   var dest = new google.maps.LatLng(41.805222,-72.254388);

   var request = {
            origin: org,
            destination:dest,
            travelMode: google.maps.TravelMode.WALKING
        };
   directionsService.route(request, function(response, status) {
            if (status == google.maps.DirectionsStatus.OK) {
                directionsDisplay.setDirections(response);
            }
        })
},

因此 map 的创建没有问题,但是当我尝试将 map 对象发送到 Google map 路线服务时,它不会呈现到我的 map 上。我已经尝试了 uconnMap.getMap() 和 uconnMap.map,但是还没有从方向服务呈现到的任何一个对象中取回对象。谁能帮帮我?

最佳答案

您需要使用以下代码::

   UConnApp.views.uconnTourMainPanel.add(uconnMap);


   directionsDisplay.setMap(uconnMap.map); // Changed this line for you…
   var org = new google.maps.LatLng(41.806501, -72.252769);
   var dest = new google.maps.LatLng(41.805222,-72.254388);

   var request = {
            origin: org,
            destination:dest,
            travelMode: google.maps.TravelMode.WALKING
        };
   directionsService.route(request, function(response, status) {
            if (status == google.maps.DirectionsStatus.OK) {
                directionsDisplay.setDirections(response);
            }
        })

现在一切正常。我刚刚在我的应用程序中为您测试了它:)

关于javascript - Sencha Touch : Can't get map object from Ext. map 提供给谷歌方向服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16022067/

相关文章:

javascript - 如何创建 JSON 数组..?

android - 应用程序构建包后,启动屏幕和启动屏幕之间出现白屏index.html sencha touch

javascript - Sencha touch 2 native 版本未加载

javascript - 防止 Google StreetView Javascript API 返回自定义全景图

javascript - 谷歌地图第二次不渲染

java - 谷歌地图 API v2 崩溃

sencha-touch-2 - 如何获取 Sencha Touch 2 应用程序中可见区域的大小

javascript - 将获取的 JSON 保存到变量中

javascript - 如何在特定区域填充颜色?

javascript - 当我将鼠标悬停在另一个图像上时使图像可见