-
-
Save milon120203/d5d02084203726e475ef794de3513d1b to your computer and use it in GitHub Desktop.
GPS Location testing
This file contains 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
var win = Ti.UI.createWindow({layout:'vertical'}); | |
var label = Ti.UI.createLabel({top:30,width:'90%',height:Ti.UI.SIZE}); | |
win.addEventListener('open',function(){ | |
Ti.Geolocation.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS, function(e){ apiInfo(JSON.stringify(e)); }); | |
}); | |
function apiInfo(msg) { | |
Titanium.UI.createAlertDialog({ | |
title: "info", | |
message:msg | |
}).show(); | |
}; | |
win.add(label); | |
win.open(); |
This file contains 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
function doClick(e) { | |
var hasLocationPermission = Ti.Geolocation | |
.hasLocationPermissions(Ti.Geolocation.AUTHORIZATION_WHEN_IN_USE); | |
if (!hasLocationPermission) { | |
Ti.Geolocation.requestLocationPermissions( | |
Ti.Geolocation.AUTHORIZATION_WHEN_IN_USE, function(e) { | |
if (e.success) { | |
getLocation(); | |
// permission granted | |
} else { | |
// permission refused | |
} | |
}); | |
}else{ | |
getLocation(); | |
} | |
function getLocation(e) { | |
Titanium.Geolocation.preferredProvider = "gps"; | |
Titanium.Geolocation.purpose = "user coordinates"; | |
Titanium.Geolocation.distanceFilter = 10; | |
Titanium.Geolocation.getCurrentPosition(function(e) { | |
if (!e.success || e.error) { | |
return; | |
} | |
var longitude = e.coords.longitude; | |
var latitude = e.coords.latitude; | |
var altitude = e.coords.altitude; | |
var heading = e.coords.heading; | |
var accuracy = e.coords.accuracy; | |
var speed = e.coords.speed; | |
var timestamp = e.coords.timestamp; | |
var altitudeAccuracy = e.coords.altitudeAccuracy; | |
Titanium.Geolocation.reverseGeocoder(latitude, longitude, function( | |
evt) { | |
if (evt.success) { | |
var places = evt.places; | |
alert('Your Current Location is : ' + places[0].address | |
+ '\n Latitude:' + latitude + '\nLongitude : ' | |
+ longitude); | |
} else { | |
Ti.API.info("Reverse geocoding error"); | |
} | |
}); | |
}); | |
} | |
} | |
$.index.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment