Last active
September 27, 2019 12:44
-
-
Save MotiurRahman/cab4828a07660fb5df771d176986f1d0 to your computer and use it in GitHub Desktop.
accuracyTest
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
// Ti SDK 8.2.0.GA | |
// Device v6.0.1 HTC m8 eye | |
var win = Ti.UI.createWindow({ | |
backgroundColor : 'white' | |
}); | |
// Create a Label. | |
var aLabel = Ti.UI.createLabel({ | |
text : 'accuracy', | |
top : 30, | |
color : 'red', | |
font : { | |
fontSize : 30 | |
}, | |
height : Ti.UI.SIZE, | |
height : Ti.UI.SIZE | |
}); | |
// Add to the parent view. | |
win.add(aLabel); | |
var gpsRule = Ti.Geolocation.Android.createLocationRule({ | |
accuracy : 20, | |
minAge : 15000 | |
}); | |
Ti.Geolocation.Android.addLocationRule(gpsRule); | |
Ti.Geolocation.accuracy = Ti.Geolocation.ACCURACY_HIGH; | |
function getAccuracy() { | |
aLabel.text = "Wait for getting accuracy"; | |
setInterval(function() { | |
Titanium.Geolocation.getCurrentPosition(function(e) { | |
try { | |
var accuracy = e.coords.accuracy; | |
aLabel.text = accuracy; | |
} catch(error) { | |
aLabel.text = error; | |
} | |
}); | |
}, 5000); | |
} | |
// Create a Button. | |
var getAccuracyData = Ti.UI.createButton({ | |
title : "Location Permission", | |
height : Ti.UI.SIZE, | |
width : Ti.UI.SIZE, | |
}); | |
function checkLocationServicesEnabled() { | |
var hasPermission = Ti.Geolocation.hasLocationPermissions(Ti.Geolocation.AUTHORIZATION_WHEN_IN_USE); | |
if (!hasPermission) { | |
Ti.Geolocation.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_WHEN_IN_USE, function(e) { | |
if (e.success) { | |
getAccuracy(); | |
} | |
}); | |
} else { | |
getAccuracy(); | |
} | |
} | |
// Listen for click events. | |
getAccuracyData.addEventListener('click', function() { | |
checkLocationServicesEnabled(); | |
}); | |
// Add to the parent view. | |
win.add(getAccuracyData); | |
win.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment