Question by
BeauBarker · Apr 23, 2018 at 06:46 AM ·
c#movementgameobjectmobileandriod
Want to move a character around a map using phones GPS
I'm trying to create an app on the phone where you use the phones GPS to move a character around on a map. I so far have been able to call the phones GPS to get the latitude and longitude, I want to cancel them out so when you first start the app it makes where you are standing 0, 0. Then as you move up or down and left or right it will be a character around on a map on your phone. This is what I have written so far but not sure if it will work with what I am looking for. Any help at all would be awesome.
public class GPS : MonoBehaviour { public static GPS Instance { set; get; }
public float latitude;
public float longitude;
public float firstLatitude;
public float currentLatitude;
public GameObject PlayerSphere;
private void Start()
{
Instance = this;
DontDestroyOnLoad (gameObject);
StartCoroutine (StartLocationService ());
}
private void Update()
{
//firstLatitude = Input.location.lastData.latitude;
currentLatitude = Input.location.lastData.latitude;
latitude = currentLatitude - firstLatitude;
PlayerSphere.transform.position.x = latitude;
}
private IEnumerator StartLocationService()
{
if (!Input.location.isEnabledByUser)
{
Debug.Log ("User has not enabled 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 ("Timed Out");
yield break;
}
if (Input.location.status == LocationServiceStatus.Failed)
{
Debug.Log ("Unable to determin device location");
yield break;
}
Input.compass.enabled = true;
firstLatitude = Input.location.lastData.latitude;
//currentLatitude = Input.location.lastData.latitude;
//longitude = Input.location.lastData.longitude;
yield break;
}
}
Comment