Version: 5.3 (switch to 5.4b)
ЯзыкEnglish
  • C#
  • JS

Язык программирования

Выберите подходящий для вас язык программирования. Все примеры кода будут представлены на выбранном языке.

LocationService.Start

Предложить изменения

Успех!

Благодарим вас за то, что вы помогаете нам улучшить качество документации по Unity. Однако, мы не можем принять любой перевод. Мы проверяем каждый предложенный вами вариант перевода и принимаем его только если он соответствует оригиналу.

Закрыть

Ошибка внесения изменений

По определённым причинам предложенный вами перевод не может быть принят. Пожалуйста <a>попробуйте снова</a> через пару минут. И выражаем вам свою благодарность за то, что вы уделяете время, чтобы улучшить документацию по Unity.

Закрыть

Отменить

Руководство
public function Start(desiredAccuracyInMeters: float = 10f, updateDistanceInMeters: float = 10f): void;
public void Start(float desiredAccuracyInMeters = 10f, float updateDistanceInMeters = 10f);
public function Start(desiredAccuracyInMeters: float = 10f, updateDistanceInMeters: float = 10f): void;
public void Start(float desiredAccuracyInMeters = 10f, float updateDistanceInMeters = 10f);
public function Start(desiredAccuracyInMeters: float = 10f, updateDistanceInMeters: float = 10f): void;
public void Start(float desiredAccuracyInMeters = 10f, float updateDistanceInMeters = 10f);

Параметры

Описание

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.

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 ();
    }
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(); } }