Reputation: 11
I got this code for getting the GPS coordinates but somehow I only got an output of the same coordinates. IT does not change the output where ever I go and sometimes I got 0 for latitude and 0 for longtitude as output please someone help me or someone have a syntax in getting the coordinates
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class testlocation : MonoBehaviour {
public void Start()
{
// turn on location services, if available
Input.location.Start();
}
public void Update()
{
Text singleText = GameObject.Find("SinglePlayerButton").GetComponentInChildren<Text>();
//Do nothing if location services are not available
if (Input.location.isEnabledByUser)
{
float lat = Input.location.lastData.latitude;
float lon = Input.location.lastData.longitude;
singleText.text = "Depart lat: " + lat + "lon: " + lon;
}
else
singleText.text = "gps off";
}
}
Upvotes: 1
Views: 12634
Reputation: 719
If you're sure the GPS is enable and there aren't any runtime errors in your code, it may be the way you're testing.
Input.location.Start() method has a default distance value to be updated. by default it has 10m, thus you need to walk 10m to see the changes. Change those values at the moment of initialitation.
Input.location.Start(10,0.1f); // accuracy, every 0.1m
Upvotes: 2