Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-8746] Android: Geolocation e.coords.longitude is returning undefined.

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-04-25T13:40:08.000+0000
Affected Version/sRelease 1.8.0.1, Release 2.0.0, Release 1.8.2
Fix Version/sRelease 2.1.0, Sprint 2012-09 API
ComponentsAndroid
LabelsSupportTeam, api, parity
ReporterNikhil Sharma
AssigneeVishal Duggal
Created2012-04-16T13:53:12.000+0000
Updated2013-01-16T22:56:17.000+0000

Description

While using the GeoLocation e.coords.longitude is returning undefined. In the below code if you comment out the "if condition" you will see the error "cannot read property 'longitude' of undefined". It's working fine in iOS.

Repo Steps

1. Run the below code in the app.js file. 2. You will get an error "gps is not available", when gps drops in android. 3. If you comment out the if condition you can see the error "cannot read property 'longitude' of undefined"
var win1 = Titanium.UI.createWindow({
	title : 'Tab 1',
	backgroundColor : '#fff'
});
Ti.Geolocation.preferredProvider = "gps";

var latitude = 33.58262112511852;
var longitude = -111.71566843986511;

var locationCallback = function(e) {
	if(!e.success || e.error) {  
		alert('error:' + JSON.stringify(e.error));  
		return;  
	}
	Ti.API.info(JSON.stringify(e));

	var longitude = e.coords.longitude;
	var latitude = e.coords.latitude;

}
Titanium.Geolocation.addEventListener('location', locationCallback);

win1.open();


Attachments

FileDateSize
android_error.png2012-04-16T13:53:12.000+000022058

Comments

  1. Vishal Duggal 2012-04-23

    Neither IOS nor Mobileweb have coords in the location event when success is false. Pull pending https://github.com/appcelerator/titanium_mobile/pull/2055
  2. Opie Cyrus 2012-04-25

    Just to clarify, the PR fixes the documentation and properly sets the event data structure in the case of error. Trying to access coords of a error event will still result in failure.
  3. Olga Romero 2012-06-23

    Verified with documentation, however an attached code will not have issues previously described.
  4. Akshay Taru 2013-01-16

    Yes, I am also facing this issue. 1. I get latitude and longitude in alert but if I try to return them nothing is returned. 2. I am getting latitude and longitude on button click, on first click (1) is observed.(Nothing returned) 3. When I again click the button, I get the latitude and longitude in return.(Every time I have to click 2 times on a button to get values) *Code :*
       
       
         Titanium.Geolocation.addEventListener('location', function(e) {
          			
          			if (e.error) {
          				
          				
          				Ti.App.geolocation={
          					
          					latitude:'',
          					longitude:'',
          					geoError: true
          					
          				};
          				alert( "Not found " );  
          				        
                   }else{
                                      
                           geoError=false;
                           Ti.App.geolocation={
          					
          					latitude:e.coords.latitude,
          					longitude:e.coords.longitude,
          					geoError: false
          					
          				};
          				alert(Ti.App.geolocation.latitude+" Inside");
                                       }              	 		
               
                });
       
       
       
       
       
    but I find nothing in *Ti.App.geolocation* on first button click on second button click I can see content

JSON Source