Results 1 to 5 of 5

Thread: Ext.device.Geolocation in native build not working on iOS

  1. #1
    Sencha User
    Join Date
    Mar 2012
    Posts
    8
    Answers
    2
    Vote Rating
    0
      0  

    Default Answered: Ext.device.Geolocation in native build not working on iOS

    Hi,

    I'm using the Ext.device.Geolocation Class to get the current Location. When I run the app as a web app via safari on iPad 1 everything works fine. If I package the exactly same app as a native app for iOS and deploy this app on my iPad1, then the callback I defined in Ext.device.Geolocation.getCurrentPosition() does not fire. I get no Location. I use the following code:

    Code:
    showMyLocation: function(){
            Ext.device.Geolocation.getCurrentPosition({
                success: function(position){
                    var myPosition = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
                    var map = this.getMapPanel().down('map').getMap();
                     var marker = new google.maps.Marker({
                        position: myPosition
                    });
                    marker.setMap(map);
                },
                failure: function(){
                    Ext.Msg.alert("Fehler", "Positionsbestimmung nicht mglich!", Ext.emptyFn);
                },
                timeout: 10000,
                scope: this
            });
        },

  2. I now use a workaround. Mayby this could help other people facing the same problem like I do. Instead of Ext.device.Geolocation I use Ext.util.Geolocation for getting a Location in the native iOS Build on iPad1.

    The following code I use:
    Code:
    showMyLocation: function(){    	if(Ext.device.Device.platform == 'iPad'){
        		var geo = Ext.create('Ext.util.Geolocation', {
        			autoUpdate: true,
        			listeners: {
        				locationupdate: function(geo){
        					var myPosition = new google.maps.LatLng(geo.getLatitude(), geo.getLongitude());
    						var map = this.getMapPanel().down('map').getMap();
    				 		var marker = new google.maps.Marker({
    							position: myPosition
    				    	});
    				    	if(this.getMapPanel().myLocationMarker != null){
    				    		this.getMapPanel().myLocationMarker.setMap(null);
    				    	}
    				    	marker.setMap(map);
    				    	this.getMapPanel().myLocationMarker = marker;
        				},
        				locationerror: function(geo, bTimeout, bPermissionDenied, bLocationUnavailable, message){
        					Ext.Msg.alert("Error:", message, Ext.emptyFn);
        				},
        				scope: this
        			}
        		});	
        		geo.updateLocation();
        	}else{
    	    	Ext.device.Geolocation.watchPosition({
    	    		callback: function(position){
    					var myPosition = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
    					var map = this.getMapPanel().down('map').getMap();
    			 		var marker = new google.maps.Marker({
    						position: myPosition
    			    	});
    			    	if(this.getMapPanel().myLocationMarker != null){
    			    		this.getMapPanel().myLocationMarker.setMap(null);
    			    	}
    			    	marker.setMap(map);
    			    	this.getMapPanel().myLocationMarker = marker;
    	    		},
    	    		failure: function(){
    	    			Ext.Msg.alert("Fehler", "Positionsbestimmung nicht mglich!", Ext.emptyFn);
    	    		},
    	    		frequency: 10000,
    	    		scope: this
    	    	});
    	    }
        },
    I did not find any other solution that works on iPad1. On Android native Build and in the mobile Safari Browser everthing works fine.

  3. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,551
    Answers
    3931
    Vote Rating
    1271
      0  

    Default

    What iOS version?
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  4. #3
    Sencha User
    Join Date
    Mar 2012
    Posts
    8
    Answers
    2
    Vote Rating
    0
      0  

    Default

    5.1 on an iPad1

  5. #4
    Sencha User
    Join Date
    Mar 2012
    Posts
    8
    Answers
    2
    Vote Rating
    0
      0  

    Default

    I now use a workaround. Mayby this could help other people facing the same problem like I do. Instead of Ext.device.Geolocation I use Ext.util.Geolocation for getting a Location in the native iOS Build on iPad1.

    The following code I use:
    Code:
    showMyLocation: function(){    	if(Ext.device.Device.platform == 'iPad'){
        		var geo = Ext.create('Ext.util.Geolocation', {
        			autoUpdate: true,
        			listeners: {
        				locationupdate: function(geo){
        					var myPosition = new google.maps.LatLng(geo.getLatitude(), geo.getLongitude());
    						var map = this.getMapPanel().down('map').getMap();
    				 		var marker = new google.maps.Marker({
    							position: myPosition
    				    	});
    				    	if(this.getMapPanel().myLocationMarker != null){
    				    		this.getMapPanel().myLocationMarker.setMap(null);
    				    	}
    				    	marker.setMap(map);
    				    	this.getMapPanel().myLocationMarker = marker;
        				},
        				locationerror: function(geo, bTimeout, bPermissionDenied, bLocationUnavailable, message){
        					Ext.Msg.alert("Error:", message, Ext.emptyFn);
        				},
        				scope: this
        			}
        		});	
        		geo.updateLocation();
        	}else{
    	    	Ext.device.Geolocation.watchPosition({
    	    		callback: function(position){
    					var myPosition = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
    					var map = this.getMapPanel().down('map').getMap();
    			 		var marker = new google.maps.Marker({
    						position: myPosition
    			    	});
    			    	if(this.getMapPanel().myLocationMarker != null){
    			    		this.getMapPanel().myLocationMarker.setMap(null);
    			    	}
    			    	marker.setMap(map);
    			    	this.getMapPanel().myLocationMarker = marker;
    	    		},
    	    		failure: function(){
    	    			Ext.Msg.alert("Fehler", "Positionsbestimmung nicht mglich!", Ext.emptyFn);
    	    		},
    	    		frequency: 10000,
    	    		scope: this
    	    	});
    	    }
        },
    I did not find any other solution that works on iPad1. On Android native Build and in the mobile Safari Browser everthing works fine.

  6. #5
    Sencha Premium Member
    Join Date
    Apr 2008
    Posts
    4
    Vote Rating
    -1
      0  

    Default

    I have the same issue. tested on iOs 5.1.1 (iPodTouch and iPad 2).
    Everything from the Ext.device Collection (Camera, Notification, ...) works except Geolocation. I've build my application with Sencha SDK 2.0 BETA 3 on Windows 7.

    If i use Ext.device.Geolocation the application crash, without any notifcation.

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
  •