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.

开始定位服务的更新。最后通过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.

服务立刻开始发送定位数据。代码应该检查iPhoneSettings.locationServiceStatus为当前服务状态。desiredAccuracyInMeters - 理想服务精确度为米。使用更高的值像500通常不需要打开GPS芯片从而保持电池电量。像5-10的值可以被用来得到最好的精确度。默认值是10米。updateDistanceInMeters - 最小的距离(单位是米)的一种服务在横向移动之前必须更新iPhoneInput.lastLocation属性。像500意味着更少的开销。默认的是10米。

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
	// 服务没有初始化在20秒内
	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();
}
最后修改:2011年4月24日 Sunday 15:30

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。