开发者

set a google marker in sencha touch

开发者 https://www.devze.com 2023-03-08 22:57 出处:网络
I have some problem when i set a marker, I found out this code for generate a google map and it works. But now i want to set a marker with my current position, and the problem is that i don\'t know wh

I have some problem when i set a marker, I found out this code for generate a google map and it works. But now i want to set a marker with my current position, and the problem is that i don't know where is the google map object, without this the marker isn't displayed.

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});
                },
             开发者_StackOverflow   locationerror: function(geo){
                  alert('got geo error');          
                }
              }
           })
    });


After spending a day searching trough google, i founded this solution:

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);

}


});


It's in:

mapg.map

You don't show what mapg is a member of but you could access it explicitly.

0

精彩评论

暂无评论...
验证码 换一张
取 消