Sencha Touch:无法从Ext.Map获取地图对象以提供给Google方向服务

时间:2013-04-15 18:17:49

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

我有一个Ext.Map对象,我试图从中获取google.maps.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);
            }
        })
},

因此创建的地图没有问题,但是当我尝试将地图对象发送到Google地图路线服务时,它将无法渲染到我的地图。我已经尝试了uconnMap.getMap()和uconnMap.map,但是没有从方向服务呈现的对象中获取对象。有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

您需要使用以下代码::

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

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