Last active
March 21, 2019 14:30
-
-
Save aminulaust/11885bba52d94749c92043b78157d37a to your computer and use it in GitHub Desktop.
location
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