GPS float precision issue!

Hi all,

Why does unity use float instead of double? I’m getting just 112.123 (longitude), about 3-4 decimals. That’s real bad. I lost many decimals/GPS accuracy just because of the data type Unity’s chosen.

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

UnitySetLastLocation(double timestamp,
                    float latitude,
                    float longitude,
                    float altitude,
                    float horizontalAccuracy,
                    float verticalAccuracy);

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
          fromLocation:(CLLocation *)oldLocation
{
    gLocationServiceStatus.locationStatus = kLocationServiceRunning;
    UnitySetLastLocation([newLocation.timestamp timeIntervalSince1970],
                        newLocation.coordinate.latitude,
                        newLocation.coordinate.longitude,
                        newLocation.altitude,
                        newLocation.horizontalAccuracy,
                        newLocation.verticalAccuracy);
}

I believe that’s very very very easy to fix. Right?

Can anyone or the Unity Team have a look at the issue?

Thanks!

Unity uses floats internally. If you need doubles, well, you’ve just found them.

Do you see the problem here? GPS coordinates are NOT in-game coordinates, they have nothing to do with what Unity uses internally. I am not asking for doubles. I am asking for solutions that can provide more accuracy than just 3-4 decimals, e.g. 114.12345678 becomes 144.123

How many meters are lost in there!?

We could use UInt32, for example, multiply by 100000000, so we have 11412345678. Whatever ways not losing the information in those numbers are better than float in this case.

GPS coordinates with that much inaccuracy are completely useless. Imagine GPS nowadays with 100-1000m error.

Yes, I know by the time these values get into Unity they are floats and useless. iOS gives you the doubles that you need. (CLLocationDegrees is typedef-ef to double.) So, until some time in the future that this is fixed, there is a solution you can use today. Will that work for you?

There is a solution that I can use today? Yes, thank you! What is it?

Get the values that are picked up in iPhone_Sensors.mm, convert them into a string, and pass them into Unity. See:

“Unity iOS supports limited native-to-managed callback functionality via UnitySendMessage:”

Yup. That will do it. Thanks!
But I think future release should fix it.

http://feedback.unity3d.com/suggestions/gps-accuracy-double

Ah, I see you found that already. :slight_smile:

Is there a similar solution for Android?

Yes, solution exists for IOS and Android.
Hope it helps to struggling with this problem: Accura GPS for Unity

It is nice but could have implemented more features from Core Location Framework for a $45 price tag. I would have bought certainly for a lower price.

There is a solution already out in the market, but not a comprehensive one.

1 Like

On the other hand it saves more time to use.
I believe it will be updated with time flow.

try this GitHub - ryanw3bb/unity-native-toolkit: Native iOS & Android functionality in Unity

I’ve run some float precision tests in the longitude latitude coordinate range (-180, +180). I found out that float precision is enough for ~0.94m at the edge of the world map. But this is the worst case. So for general use of GPS I wouldn’t worry too much.

Details:

Float’s precision around values of +180 is 0.000016
Float’s precision around values of +1 is 0.00000006

For example in North-West USA, Portland, float’s coordinates have the accuracy of 0.1 meters.

So if you don’t want to send missiles to mice with your app, float is just fine :slight_smile:

How did I tested?

I opened the two links below, first compared them by pressing TAB in browser (you can do that easily), but I took screenshots, compared the shift at the edge of the screenshots (or grid is also good above the screenshot on a second layer), When I’ve seen the amount of shift, I went back to google map and measured that distance. North-West USA, Portland:

You can see the coordinates above, I added the worst case float precision 0.000016 to the second one. Note that precision is better here because coordinates are not around 180 but only ~122 and ~45, but I took the worst case.

I made this kind of thest in North-Canada and Japan where coordinates are big. If you live in a country when coordinates are smaller gps accuracy with float is even better. E.g. in Paris float precision is 0.01m or less.

And if you are interested, here are my c# test for float precision:

    public void Test1()
    {
        double step = 0.000016;  // float fails badly with 0.000015 , but 0.000016 is good!
        RunFloatTest(-181, step);
        RunFloatTest(-001, step);
        RunFloatTest(+179, step);
    }
    private void RunFloatTest(double start, double step)
    {
        double end = start + 2.0;
        float prevfloat = float.MinValue;
        float f;
        long sameCount = 0;
        long count = 0;
        for (double d = start; d <= end; d += step)
        {
            f = (float)d;
            if (f == prevfloat) sameCount++;
            prevfloat = f;
            count++;
        }
        Mydebug.LogFormat("Samecount: {0} ({1}%)", sameCount, (double)sameCount / count * 100.0);
    }
1 Like

We really need to have the double. It would make the AR experience even better.

I develop an outdoor GPS based MMO AR game using Unity. It uses the default location system. In general players get 3m accuracy in most wooded conditions and 10m indoors. Since it is a territory control game fought with paintball guns, each “Control Point” has a “10 meter gps center”. Cross the 10m circle and the player begins capturing that location for their side. They have to stay within 25 meters for 3 minutes. This has been the best overall distance and timing setup for the game mechanics to work in the real world.

Feedback site is no more. Are there anywhere we could track this feature?