返回介绍

LocationService.Start 开始

发布于 2019-12-18 15:37:56 字数 4919 浏览 1111 评论 0 收藏 0

JavaScript => public function Start(desiredAccuracyInMeters: float = 10f, updateDistanceInMeters: float = 10f): void;
C# => public void Start(float desiredAccuracyInMeters = 10f, float updateDistanceInMeters = 10f);

Parameters 参数

Description 描述

Starts location service updates. Last location coordinates could be.

开始更新位置服务。是最新的位置坐标。

Retrieved via Input.location.lastData. Service does not start to send location data immediately. Code should check Input.location.status 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 Input.location property is updated. Higher values like 500 imply less overhead. Default is 10 meters.

恢复渠道Input.location.lastData。服务没有立即发送位置数据。代码应该检查Input.location.status确定当前服务状态。desiredAccuracyInMeters -要求服务精准单位米。使用较高的值例如500通常不需要打开GPS芯片,这样可以更节省电池电量。像5-10值可能获取的更精确。默认值是10米。updateDistanceInMeters -最小距离(测量单位米)Input.location 属性更新之前,设备必须横向移动。较高的值像 500 意味着更少的开销。默认10米。

JavaScript:

function Start () {
        // First, check if user has location service enabled
        if (!Input.location.isEnabledByUser)
            return;
        // Start service before querying location
        Input.location.Start ();
        // Wait until service initializes
        var maxWait : int = 20;
        while (Input.location.status
               == LocationServiceStatus.Initializing && maxWait > 0) {
            yield WaitForSeconds (1);
            maxWait--;
        }
        // Service didn't initialize in 20 seconds
        if (maxWait < 1) {
            print ("Timed out");
            return;
        }
        // Connection has failed
        if (Input.location.status == LocationServiceStatus.Failed) {
            print ("Unable to determine device location");
            return;
        }
        // Access granted and location value could be retrieved
        else {
            print ("Location: " + Input.location.lastData.latitude + " " +
                   Input.location.lastData.longitude + " " +
                   Input.location.lastData.altitude + " " +
                   Input.location.lastData.horizontalAccuracy + " " +
                   Input.location.lastData.timestamp);
        }
        // Stop service if there is no need to query location updates continuously
        Input.location.Stop ();
    }

C#:

using UnityEngine;
using System.Collections;
 
public class TestLocationService : MonoBehaviour
{
    IEnumerator Start()
    {
        // First, check if user has location service enabled
        if (!Input.location.isEnabledByUser)
            yield break;
 
        // Start service before querying location
        Input.location.Start();
 
        // Wait until service initializes
        int maxWait = 20;
        while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
        {
            yield return new WaitForSeconds(1);
            maxWait--;
        }
 
        // Service didn't initialize in 20 seconds
        if (maxWait < 1)
        {
            print("Timed out");
            yield break;
        }
 
        // Connection has failed
        if (Input.location.status == LocationServiceStatus.Failed)
        {
            print("Unable to determine device location");
            yield break;
        }
        else
        {
            // Access granted and location value could be retrieved
            print("Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp);
        }
 
        // Stop service if there is no need to query location updates continuously
        Input.location.Stop();
    }
}

locationservice

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文