consolidate all repos to one for archive
This commit is contained in:
74
projektna_naloga/ar_map/Assets/Scripts/gps_location.cs
Normal file
74
projektna_naloga/ar_map/Assets/Scripts/gps_location.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class gps_location : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI status;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
StartCoroutine(GPSLocation());
|
||||
}
|
||||
|
||||
IEnumerator GPSLocation()
|
||||
{
|
||||
// Check if location is enabled
|
||||
if (!Input.location.isEnabledByUser)
|
||||
{
|
||||
status.text = "Location not enabled";
|
||||
yield break;
|
||||
}
|
||||
|
||||
// Start service before querying locaction
|
||||
Input.location.Start();
|
||||
|
||||
// Wait until service is intilized
|
||||
int maxWait = 20;
|
||||
while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
|
||||
{
|
||||
status.text = "Calibrating...";
|
||||
|
||||
yield return new WaitForSeconds(1);
|
||||
maxWait -= 1;
|
||||
}
|
||||
|
||||
// Service didn't initilize in 20 seconds
|
||||
if (maxWait < 1)
|
||||
{
|
||||
status.text = "Service didn't initilize in 20s";
|
||||
|
||||
yield break;
|
||||
}
|
||||
|
||||
if (Input.location.status == LocationServiceStatus.Failed)
|
||||
{
|
||||
status.text = "Failed to connect to location";
|
||||
yield break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// access granted
|
||||
InvokeRepeating("UpdateGPSData", 0.5f, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void UpdateGPSData()
|
||||
{
|
||||
if (Input.location.status == LocationServiceStatus.Running)
|
||||
{
|
||||
// Access granted to GPS value and it has been initlized
|
||||
status.text = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
status.text = "Service stopped";
|
||||
// service stopped
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user