iPhoneSettings.StartLocationServiceUpdates Manual     Reference     Scripting  
Scripting > Runtime Classes > iPhoneSettings
iPhoneSettings.StartLocationServiceUpdates

static function StartLocationServiceUpdates (desiredAccuracyInMeters : float = 10f, updateDistanceInMeters : float = 10f) : void

Description

Starts location service updates. Last location coordinates could be retrieved via iPhoneInput.lastLocation.

Service does not start to send location data immediately. Code should check iPhoneSettings.locationServiceStatus for current service status. desiredAccuracyInMeters - desired service accuracy in meters. Using higher value like 500 usually does not require to turn GPS chip on and thus saves battery power. Values like 5-10 could be used for getting best accuracy. Default value is 10 meters. updateDistanceInMeters - the minimum distance (measured in meters) a device must move laterally before iPhoneInput.lastLocation property is updated. Higher values like 500 imply less overhead. Default is 10 meters.

function Start () {
// Start service before querying location
iPhoneSettings.StartLocationServiceUpdates();

// Wait until service initializes
var maxWait : int = 20;
while (iPhoneSettings.locationServiceStatus ==
LocationServiceStatus.Initializing && maxWait > 0) {
yield WaitForSeconds(1);
maxWait--;
}

// Service didn't initialize in 20 seconds
if (maxWait < 1) {
print("Timed out");
return;
}

// User denied access to device location
if (iPhoneSettings.locationServiceStatus == LocationServiceStatus.Failed) {
print("User denied access to device location");
return;
}
// Access granted and location value could be retrieved
else {
print("Location: " + iPhoneInput.lastLocation.latitude + " " +
iPhoneInput.lastLocation.longitude + " " +
iPhoneInput.lastLocation.altitude + " " +
iPhoneInput.lastLocation.horizontalAccuracy + " " +
iPhoneInput.lastLocation.timestamp);

}

// Stop service if there is no need to query location updates continuously
iPhoneSettings.StopLocationServiceUpdates();
}