Set google token in sencha touch

I have some problem, when I set the marker, I recognized this code to create google map and it works. But now I want to set a marker with my current position, and the problem is that I do not know where the google map object is located , without this the marker does not appear.

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
source share
2 answers

After spending a day searching google, I based 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);

}


});
+3
source

This is in:

mapg.map

You do not show which mapg member is a member, but you can access it explicitly.

0
source

All Articles