Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Precision of Location longitude is worse when longitude is beyond 100 degrees

Discussion in 'Editor & General Support' started by Claude23, Apr 22, 2012.

  1. Claude23

    Claude23

    Joined:
    Aug 6, 2011
    Posts:
    4
    According to Unity Scripting Rerference, LocationInfo.longitude is a float number.http://unity3d.com/support/documentation/ScriptReference/LocationInfo-longitude.html
    I guess the real value given by the GPS is then truncated to a Single-precision floating-point format within Unity.
    Therefore, if I am, let say, in Manchester (Europe), my LocationInfo.longitude value would be something like -2.247926 degrees (6 decimals), meaning that I could have a horizontal location accuracy below 1 meter (although hardware accuracy will be no better than 2-5 meters).
    However if I am in Los Angeles, the value for LocationInfo.longitude would be something like -118.2436 degrees (4 decimals), given that a float number cannot show more than 7 digits(including integer and decimal part). In conclusion, my Unity app using GPS would have way more than 10 meters accuracy in Los Angeles or any other longitude with a 3 digits integer part.
    Can anyone confirm this issue? Am I missing something? Is there any way to avoid this?

    Cheers.
     
    kenjichanhkg likes this.
  2. kenjichanhkg

    kenjichanhkg

    Joined:
    May 5, 2014
    Posts:
    6
    Hi, I'm into the same issue!

    Why does unity use float instead of double? I'm getting 112.123 (longitude), about 3-4 decimals. That's real bad, and this post is from 2011.....OMG.

    For iOS, in iPhone_Sensors.mm, I've found these lines.
    Unity casts a double into a float.

    Code (CSharp):
    1. UnitySetLastLocation(double timestamp,
    2.                     float latitude,
    3.                     float longitude,
    4.                     float altitude,
    5.                     float horizontalAccuracy,
    6.                     float verticalAccuracy);
    7.  
    8. - (void)locationManager:(CLLocationManager *)manager
    9.     didUpdateToLocation:(CLLocation *)newLocation
    10.           fromLocation:(CLLocation *)oldLocation
    11. {
    12.     gLocationServiceStatus.locationStatus = kLocationServiceRunning;
    13.     UnitySetLastLocation([newLocation.timestamp timeIntervalSince1970],
    14.                         newLocation.coordinate.latitude,
    15.                         newLocation.coordinate.longitude,
    16.                         newLocation.altitude,
    17.                         newLocation.horizontalAccuracy,
    18.                         newLocation.verticalAccuracy);
    19. }


    I believe that's very very very easy to fix. Right?
     
  3. Talimar

    Talimar

    Joined:
    Dec 28, 2012
    Posts:
    3
    I spent weeks trying to solve my GPS issues over a year ago and gave up. I started again this weekend determined to resolve it. My Haversine distance function was reporting a distance even when the lat/long were identical. I tore my hair out for 2 days straight, until I discovered that floats have an internal accuracy of 9 digits. If you print your lat/long with .ToString("R") you'll see the extra precision is retained from the cast to float, but standard ToString() will only show you 7 digits of accuracy.
     
  4. yuhgw

    yuhgw

    Joined:
    Jul 2, 2018
    Posts:
    1
    actually doesn't work.
     
    ironbitUnity likes this.
  5. R0man

    R0man

    Joined:
    Jul 10, 2011
    Posts:
    88
    I believe this is to the use of lead paint at the Unity offices. Can anyone at Unity confirm?
     
    victor_unity395 and rogerjcottam like this.
  6. hark313

    hark313

    Joined:
    Jun 22, 2017
    Posts:
    3
    Still now working.
     
  7. asa989

    asa989

    Joined:
    Dec 18, 2015
    Posts:
    52
    Does not work in 2020 either. though what actually works in 2020 anyway??!
     
    resulalici likes this.
  8. jan-rb

    jan-rb

    Joined:
    Oct 26, 2020
    Posts:
    9
    Same problems here.
    Why is Unity using only float precision for Latitude and Longitude?
    This problem is 8 years old and still not fixed.
    Please Unity devs, it's 2021 and we still only get floating point precision for sensor data which has a way better precision internally.
    That's really a shame and would be so easy to fix.
     
    daveMennenoh and rogerjcottam like this.
  9. asa989

    asa989

    Joined:
    Dec 18, 2015
    Posts:
    52
    because some graphic cards dont accept double. Specially most phone GPUs
     
  10. burlingk

    burlingk

    Joined:
    Dec 28, 2014
    Posts:
    4
    The CPUs will as a general rule though.
     
  11. burlingk

    burlingk

    Joined:
    Dec 28, 2014
    Posts:
    4
    The solution, though, in short, is to use longitude.ToString("R").

    Honestly, from there, a lot of what you will end up using it for will accept strings, anyway.