You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.3 KiB
53 lines
1.3 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class GPS : MonoBehaviour
|
|
{
|
|
|
|
public static GPS Instance { set; get; }
|
|
|
|
public float latitude; //위도
|
|
public float longitude; //경도
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
Instance = this;
|
|
DontDestroyOnLoad(gameObject);
|
|
StartCoroutine(StartLocationService());
|
|
}
|
|
|
|
private IEnumerator StartLocationService()
|
|
{
|
|
if (!Input.location.isEnabledByUser)
|
|
{
|
|
Debug.Log("GPS없다");
|
|
yield break;
|
|
}
|
|
Input.location.Start();
|
|
int maxWait = 20;
|
|
while(Input.location.status==LocationServiceStatus.Initializing && maxWait > 0)
|
|
{
|
|
yield return new WaitForSeconds(1);
|
|
maxWait--;
|
|
|
|
|
|
}
|
|
if(maxWait <= 0)
|
|
{
|
|
Debug.Log("없음");
|
|
yield break;
|
|
}
|
|
if(Input.location.status == LocationServiceStatus.Failed)
|
|
{
|
|
Debug.Log("Unable to determin device location");
|
|
yield break;
|
|
}
|
|
latitude = Input.location.lastData.latitude;
|
|
longitude = Input.location.lastData.longitude;
|
|
yield break;
|
|
|
|
}
|
|
// Update is called once per frame
|
|
}
|