我正在加载我的谷歌地图并想显示我的路线。当我将听众放在地图下方时,它工作得很好。
{
xtype: 'map',
flex: 1,
mapOptions: {
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP,
},
listeners: {
maprender : function(comp, map){;
var directionsDisplay = new google.maps.DirectionsRenderer();
var directionsService = new google.maps.DirectionsService();
directionsDisplay.setMap(map);
var start = 'New York';
var end = 'Chicago';
var request = {
origin:start,
destination:end,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
}
当我将侦听器移动到 updateRecord 以便我可以从我的记录中放置开始和结束时,我的 maprender 侦听器不会启动。
updateRecord: function(newRecord) {
if (newRecord) {
var record = newRecord;
this.down('map').setListeners({
maprender : function(comp, map){
var tripsStore= Ext.getStore('Trips');
var directionsDisplay = new google.maps.DirectionsRenderer();
var directionsService = new google.maps.DirectionsService();
directionsDisplay.setMap(map);
//alert("ok pressed");
console.log
var start = record.data.from;
var end = record.data.to;
var request = {
origin:start,
destination:end,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
});
}
},
有什么想法可以解决这个问题吗?