Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-15261] Android: Geolocation calls fail with "network unavailable" on Galaxy Note 2

GitHub Issuen/a
TypeBug
PriorityLow
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 3.1.2
Fix Version/sn/a
ComponentsAndroid
Labelsn/a
ReporterTim Poulsen
AssigneeUnknown
Created2013-09-18T01:17:47.000+0000
Updated2018-02-28T20:04:15.000+0000

Description

Attempting to obtain a location on a Galaxy Note 2 returns a "network unavailable" error and no location data. The same code works on other Android devices. Drop this into a traditional project:
var win = Ti.UI.createWindow({
	backgroundColor: 'white'
});

var updatedLongitudeLabel = Titanium.UI.createLabel({
    text:'Updated Location',
    font:{fontSize:'12dip', fontWeight:'bold'},
    color:'#111',
    top:240,
    left:10,
    height:Ti.UI.SIZE,
    width:300
});
win.add(updatedLongitudeLabel);

var updatedLongitude = Titanium.UI.createLabel({
    text:'no longitude yet',
    font:{fontSize:'12dip'},
    color:'#444',
    top:260,
    left:10,
    height:Ti.UI.SIZE,
    width:300
});
win.add(updatedLongitude);

var updatedLatitude = Titanium.UI.createLabel({
    text:'no latitude yet',
    font:{fontSize:'12dip'},
    color:'#444',
    top:280,
    left:10,
    height:Ti.UI.SIZE,
    width:300
});
win.add(updatedLatitude);


win.open();

Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_HIGH;
var locationAdded = false; 
var locationCallback = function(e) {
    if (!e.success || e.error) {
    	// if there's an error ...
        updatedLongitude.text = 'error:' + JSON.stringify(e.error);
        updatedLatitude.text = '';
        return;
    }

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

    updatedLongitude.text = 'long:' + longitude;
    updatedLatitude.text = 'lat: '+ latitude;

	locationAdded = true;
    Titanium.API.info('geo - location updated: ' + new Date(timestamp) + ' long ' + longitude + ' lat ' + latitude + ' accuracy ' + accuracy);
};
Titanium.Geolocation.addEventListener('location', locationCallback);
Code here is a simplified version of the Android geolocation example at https://github.com/appcelerator-training/AndroidGeo

Comments

No comments

JSON Source