1

Hi I am using the below code to the get the Latitudes and Longitudes form an IOS device.The problem is I am getting only upto four points.So I read in blogs we need to use double to get more decimal points and Unity API only supports 4 decimal points or upto 6 decimal points for latitudes .In order to get accurate Lat/Long values we require more decimal points.(Eg:8.8382738239232032,120.23232328347823782323).How to get more decimal values.

void Start ()
{
    StartCoroutine(Getdata());
}



IEnumerator Getdata()
{
    // First, check if user has location service enabled
    if (!Input.location.isEnabledByUser)
        yield break;


// Start service before querying location
Input.location.Start();

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

// Service didn't initialize in 20 seconds

if (maxWait < 1)
{
    print("Timed out");
    yield break;
}
// Connection has failed
if (Input.location.status == LocationServiceStatus.Failed)
{
    print("Unable to determine device location");
    yield break;
}
else
{




    double aa= Input.location.lastData.latitude;
    Debug.Log("Double Latitude="+aa);

    latitudes = double.Parse(Input.location.lastData.latitude.ToString("R"));
    longitudes = double.Parse(Input.location.lastData.longitude.ToString("R"));
    altitudes = double.Parse(Input.location.lastData.altitude.ToString("R"));
    deviceinfo = SystemInfo.deviceModel;
// Access granted and location value could be retrieved
Locationinformation.text = "Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp;
print("Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp);
}

// Stop service if there is no need to query location updates continuously
Input.location.Stop();
}

1 Answer 1

2

I know of 2 option here: Either use an additional asset like this one accura-gps-for-unity or get the values that are picked up in iPhone_Sensors.mm then you convert them into a string, and finally pass them into Unity. Use this guid PluginsForIOS

1
  • How to get the values from iPhone_Sensors.mm. You mean I have to create a plugin for unity?iPhone_Sensors.mm Where to find it?
    – zyonneo
    Oct 29, 2018 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.