[TIMOB-8746] Android: Geolocation e.coords.longitude is returning undefined.
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2012-04-25T13:40:08.000+0000 |
Affected Version/s | Release 1.8.0.1, Release 2.0.0, Release 1.8.2 |
Fix Version/s | Release 2.1.0, Sprint 2012-09 API |
Components | Android |
Labels | SupportTeam, api, parity |
Reporter | Nikhil Sharma |
Assignee | Vishal Duggal |
Created | 2012-04-16T13:53:12.000+0000 |
Updated | 2013-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
File | Date | Size |
---|---|---|
android_error.png | 2012-04-16T13:53:12.000+0000 | 22058 |
Neither IOS nor Mobileweb have coords in the location event when success is false. Pull pending https://github.com/appcelerator/titanium_mobile/pull/2055
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.
Verified with documentation, however an attached code will not have issues previously described.
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 :*
but I find nothing in *Ti.App.geolocation* on first button click on second button click I can see content