GPS Bilgilerini Alma

kubricklynch

Hectopat
Katılım
12 Şubat 2021
Mesajlar
314
Çözümler
6
Yer
İstanbul
Arkadaşlar yazdığım gps bilgilerini 1 saniye ara ile almaya ayarladığımı düşünüyorum ama uygulamada güncellemiyor. Programı kapatıp açınca güncelliyorum bir hata mı var acaba?
[CODE lang="csharp" title="GPS"]using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class GPSLocation : MonoBehaviour
{
public Text GPSStatus;
public Text latValue;
public Text lonValue;
public Text altValue;
public Text horAccValue;
public Text timeStampValue;

// Start is called before the first frame update
void Start()
{
StartCoroutine(GPSLoc());
}

IEnumerator GPSLoc()
{
if (!Input.location.isEnabledByUser)
yield break;
Input.location.Start();

int maxWait = 20;
while(Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
{
yield return new WaitForSeconds(1);
maxWait--;
}

if(maxWait < 1)
{
GPSStatus.text = "Time Out";
yield break;
}

if(Input.location.status == LocationServiceStatus.Failed)
{
GPSStatus.text = "Unable to reach device location.";
yield break;
}
else
{
GPSStatus.text = "Running";
InvokeRepeating("UpdateGPSData", 1f, 1f);
}
}

private void UpdateGPSData()
{
if(Input.location.status == LocationServiceStatus.Running)
{
GPSStatus.text = "Running";
latValue.text = Input.location.lastData.latitude.ToString();
lonValue.text = Input.location.lastData.longitude.ToString();
altValue.text = Input.location.lastData.altitude.ToString();
horAccValue.text = Input.location.lastData.horizontalAccuracy.ToString();
timeStampValue.text = Input.location.lastData.timestamp.ToString();
}
else
{

}
}
}[/CODE]
 
Uyarı! Bu konu 5 yıl önce açıldı.
Muhtemelen daha fazla tartışma gerekli değildir ki bu durumda yeni bir konu başlatmayı öneririz. Eğer yine de cevabınızın gerekli olduğunu düşünüyorsanız buna rağmen cevap verebilirsiniz.

Technopat Haberler

Geri
Yukarı