2013-08-25 88 views
0

我想向Google地图添加标记。问题是我的网站是'Ext.Container'而不是'Ext.map',因为我需要一个标题栏。这就是getMap()不适合我的原因。有机会得到这个运行?Sencha Touch - 将标记添加到地图

这是绘制地图的功能:

showMapCommand: function() { 
    var record = this.getRecord(); 

    var map = new Ext.Map({ 
     title: 'Map', 
     useCurrentLocation: false, 
     mapOptions: { 
      mapTypeId: google.maps.MapTypeId.ROADMAP, 
      center: new google.maps.LatLng(record.data.latitude, record.data.longitude), 
      mapTypeControl: false, 
      zoomControl: true, 
      overviewMapControl: false, 
      panControl: false, 
      rotateControl: false, 
      scaleControl: false, 
      controlPosition: false, 
      navigationControl: false, 
      streetViewControl: false, 
      backgroundColor: 'transparent', 
      disableDoubleClickZoom: true, 
      zoom: 15, 
      keyboardShortcuts: false, 
      scrollwheel: false 
     } 
    }); 

    var marker = new google.maps.Marker ({ 
     map: map, 
     animation: google.maps.Animation.DROP, 
     position: new google.maps.LatLng(record.data.latitude, record.data.longitude), 
     icon: 'resources/images/marker.png' 
    }); 

    this.add([ 
     map 
    ]); 
}, 

控制台的错误消息:

Uncaught Error: Invalid value for property <map>: [object Object] 

回答

0

试试这个:

var marker = new google.maps.Marker ({ 
    map: map.map, 
    animation: google.maps.Animation.DROP, 
    position: new google.maps.LatLng(record.data.latitude, record.data.longitude), 
    icon: 'resources/images/marker.png' 
}); 

希望helps-

编辑

为什么不创建一个单独的文件与Ext.defining您的地图,你只需将它添加为您的容器项目。这样你可以this.getMap()

+0

现在我没有收到错误信息,但仍然没有标记。 – torhoehn

+0

为什么不用Ext创建一个单独的文件来定义你的地图,而只是将它添加为你的容器的一个项目。这样你可以this.getMap() –