2011-05-27 69 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