Last active
December 30, 2015 18:39
-
-
Save MotiurRahman/7868936 to your computer and use it in GitHub Desktop.
Getting stale location if providers turned off , irrespective of LocationRule.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Hi, I have tested this jira ticket. I think its may be bug according to the reporter question. | |
If we run this code and turned on GPS Network setting and click the userLocation button get the current location. | |
But if we turned off the GPS Network setting and click the button we also get stale location and That location should have | |
been filtered by rules but in this case does not happen. | |
Testing Environment: | |
Titanium SDK: 3.1.3 | |
Android SDK:4.2.2 | |
Steps to reproduce: | |
1. create a simple project | |
2.Paste this code in app.js file | |
3.Run this in a real device with testing environment | |
*/ | |
var win = Ti.UI.createWindow({ | |
title : 'Stale Location', | |
navBarHidden : false, | |
layout : 'vertical' | |
}); | |
// Create a Button. | |
var userLocation = Ti.UI.createButton({ | |
title : 'userLocation', | |
height : Ti.UI.SIZE, | |
width : Ti.UI.SIZE, | |
top : 10 | |
}); | |
// Add to the parent view. | |
win.add(userLocation); | |
// Create a label. | |
var reverseGeoLabel = Titanium.UI.createLabel({ | |
text : 'Your Current Location', | |
font : { | |
fontSize : 15, | |
fontWeight : 'bold' | |
}, | |
color : '#fff', | |
top : 10, | |
left : 10, | |
height : Ti.UI.SIZE, | |
width : Ti.UI.SIZE | |
}); | |
// Add to the parent view. | |
win.add(reverseGeoLabel); | |
// Create a label. | |
var reverseGeo = Titanium.UI.createLabel({ | |
text : '', | |
font : { | |
fontSize : 12 | |
}, | |
color : '#fff', | |
top : 10, | |
left : 10, | |
height : Ti.UI.SIZE, | |
width : Ti.UI.SIZE | |
}); | |
win.add(reverseGeo); | |
Titanium.Geolocation.Android.manualMode = true; | |
var providerGps = Ti.Geolocation.Android.createLocationProvider({ | |
name : Ti.Geolocation.PROVIDER_GPS, | |
}); | |
var providerNetwork = Ti.Geolocation.Android.createLocationProvider({ | |
name : Ti.Geolocation.PROVIDER_NETWORK, | |
}); | |
//add the providers | |
Ti.Geolocation.Android.addLocationProvider(providerGps); | |
Ti.Geolocation.Android.addLocationProvider(providerNetwork); | |
var maxAgeMili = 1 * 60 * 1000; | |
// 1 minute | |
var minAgeMili = 1 * 1000; | |
//1 second | |
var gpsRule = Ti.Geolocation.Android.createLocationRule({ | |
provider : Ti.Geolocation.PROVIDER_GPS, | |
accuracy : 50, | |
maxAge : maxAgeMili, | |
minAge : minAgeMili | |
}); | |
var networkRule = Ti.Geolocation.Android.createLocationRule({ | |
provider : Ti.Geolocation.PROVIDER_NETWORK, | |
accuracy : 50, | |
maxAge : maxAgeMili, | |
minAge : minAgeMili | |
}); | |
Ti.Geolocation.Android.addLocationRule(gpsRule); | |
Ti.Geolocation.Android.addLocationRule(networkRule); | |
// Listen for click events. | |
userLocation.addEventListener('click', function() { | |
Titanium.Geolocation.addEventListener('location', function(e) { | |
if (e.error) { | |
alert('Error: ' + e.error); | |
} else { | |
var longitude = e.coords.longitude; | |
var latitude = e.coords.latitude; | |
Ti.Geolocation.reverseGeocoder(latitude, longitude, function(e) { | |
var places = e.places; | |
//reverseGeo.text = places[0].address; | |
var place = places[0].address; | |
//alert(place); | |
reverseGeo.setText(place); | |
}); | |
} | |
}); | |
}); | |
win.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment