繁体   English   中英

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

[英]Sencha Touch: Can't get map object from Ext.Map to give to the google directions service

我有一个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 Maps路线服务时,它不会渲染到我的地图上。 我已经尝试了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);
            }
        })

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM