2011-05-27 49 views
3

我设置标记时出现了一些问题,我发现这个代码用于生成谷歌地图并且工作正常。但现在我想设置一个标记与我目前的位置,问题是,我不知道哪里是谷歌地图对象,没有这个标记不显示。在sencha touch中设置谷歌标记

this.mapg = new Ext.Map({ 
     useCurrentLocation:true, 
     geo:new Ext.util.GeoLocation({ 
       autoUpdate:true, 
       timeout:2000, 
       listeners:{ 
       locationupdate: function(geo) { 
        center = new google.maps.LatLng(geo.latitude, geo.longitude); 

        // Set the marker 
        marker = new google.maps.Marker({ 
        map:geo.map,//??? No idea where is the google map object 
        position: center 
        }); 

       if (this.rendered) 
        this.update(center); 
        else 
        this.on('activate', this.onUpdate, this, {single: true, data: center}); 
       }, 
       locationerror: function(geo){ 
        alert('got geo error');   
       } 
       } 
      }) 
    }); 

回答

3

每天花费在搜索槽谷歌后,我创办这个解决方案:

ascom.views.MapG = Ext.extend(Ext.Panel, { 

layout:'card', 
initComponent: function(){ 

    var infowindow = new google.maps.InfoWindow({ 
     content: 'prova' 
    }); 

    this.map = new Ext.Map({ 
     mapOptions : { 
      zoom: 12, 
      navigationControlOptions: { 
       style: google.maps.NavigationControlStyle.DEFAULT 
      } 
     }, 
     useCurrentLocation: true, 
     listeners: { 
      maprender : function(comp, map){ 
       var marker = new google.maps.Marker({ 
        position: map.center, 
        title : 'Infofactory HQ', 
        map: map 
       }); 

       infowindow.open(map, marker); 

       google.maps.event.addListener(marker, 'click', function() { 
        infowindow.open(map, marker); 
       }); 
      } 
     } 
    }); 

    this.panel = new Ext.Panel({ 
     layout:'fit', 
     items:this.map, 
     dockedItems:[ 
      { 
       xtype:'toolbar', 
       title:'Map GO' 
      } 
     ] 
    }); 

    this.items = this.panel; 
    ascom.views.MapG.superclass.initComponent.call(this); 

} 


}); 
+0

很好的例子,但信息窗口才会打开,因为它明确地解雇 - 信息窗口。打开。点击事件侦听器似乎不适合我。我也试过'点击' - 没有运气让这个响应用户交互 - 在iOS6和iOS7上测试。其他人得到这个问题? – barneymc 2013-11-12 22:35:08

0

它在:

mapg.map 

你不显示什么mapg是的成员,但你可以明确地访问它。

+0

我都试过,但mapg.map永远是不确定的 – USSliberty 2011-05-31 12:57:45