Results 1 to 3 of 3

Thread: Add geolocation to map component using locationupdate event

  1. #1

    Default Answered: Add geolocation to map component using locationupdate event

    I have the following code. I am trying to add a marker for the uses current location. The onLocationUpdate function is being called successfully and I can access the geo data in this function.

    My problem is accessing the map from this function to manipulate markers etc.

    Does anyone know how I can access the map component from the onlocationupdate function or am I going about this all incorrectly.



    Code:
    test.views.MapView = Ext.extend(Ext.Panel, {
    	layout: 'card',
        initComponent: function() {
    
    
            this.map = new Ext.Map({
            	useCurrentLocation: true,
                mapOptions : {
                    zoom: 16,
                    navigationControlOptions: {
                        style: google.maps.NavigationControlStyle.DEFAULT
                    }
                },
    			geo: new Ext.util.GeoLocation({
    				autoUpdate: false,
    				timeout: 1000,
    				listeners: {
    					locationupdate: this.onLocationUpdate,
    					scope: this,
    					locationerror: function(geo) {
    						console.log('Location update error.');
    					}
    				}
    			})
            });
            
            this.items = this.map;
            
            test.views.MapView.superclass.initComponent.call(this);
        },
        onLocationUpdate: function(geo) {
    
    
        	var position = new google.maps.LatLng(geo.latitude, geo.longitude);
    
    
    		var infowindow = new google.maps.InfoWindow({
    			content: 'test info text'
    		});
            
        	var marker = new google.maps.Marker({
                 position: position,
                 title : 'Your location!',
                 map: this.map
            });
        }
    });
    
    
    Ext.reg('mapview', test.views.MapView);

  2. this.map is the Ext.Map instance but you want the Google Map instance which would be at this.map.map

  3. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,448
    Answers
    3997

    Default

    this.map is the Ext.Map instance but you want the Google Map instance which would be at this.map.map
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

  4. #3

    Default

    Thank you Mitchell. Just what I was looking for.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •