Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Unity 4.0 iOS GPS Fix

Discussion in 'iOS and tvOS' started by Jodon, Nov 20, 2012.

  1. Jodon

    Jodon

    Joined:
    Sep 12, 2010
    Posts:
    434
    Hello,

    I'm at Leaping Coyote (www.leapingcoyote.com) right now, working on an iOS game that uses GPS. It looks like a bug crept into Unity 4.0 that gives bad values for the GPS data. If you're seeing the same thing, here is how to solve that:

    open up iPhone_Sensors.mm
    Look for the code that calls UnitySetLastLocation. Notice how the timestamp is the last parameter? It should actually be the first parameter. Here is the rewritten section:


    Code (csharp):
    1. // Delegate method from the CLLocationManagerDelegate protocol.
    2. - (void)locationManager:(CLLocationManager *)manager
    3.     didUpdateToLocation:(CLLocation *)newLocation
    4.            fromLocation:(CLLocation *)oldLocation
    5. {
    6.     gLocationServiceStatus.locationStatus = kLocationServiceRunning;
    7.  
    8.     UnitySetLastLocation([newLocation.timestamp timeIntervalSince1970],
    9.                          newLocation.coordinate.latitude,
    10.                          newLocation.coordinate.longitude,
    11.                          newLocation.altitude,
    12.                          newLocation.horizontalAccuracy,
    13.                          newLocation.verticalAccuracy);
    14. }
    15.  
    Cheers.
     
  2. jderrough

    jderrough

    Joined:
    Apr 1, 2011
    Posts:
    6
    Thank you so much for that! :)
     
  3. Nub3h

    Nub3h

    Joined:
    Aug 23, 2012
    Posts:
    56
    Hi, I have the same issue...I checke with the file but the timestamp is already at the right place...but I installed Unity 4 only yesterday so they fixed it maybe. Anyway I still have my GPS coordinates totally wrong :(, any other solution?
     
  4. mtalbott

    mtalbott

    Joined:
    Dec 21, 2011
    Posts:
    125
    thank you so much for figuring this out! this was killing me. I could tell something was shifted because I was getting an expected longitude in the latitude parameter but never would have figured out what was off.
     
  5. blockimperium

    blockimperium

    Joined:
    Jan 21, 2008
    Posts:
    452
    I confirm that this is fubar in the shipping version of 4.0.
     
  6. TommiH

    TommiH

    Joined:
    Jan 14, 2008
    Posts:
    253
    Robin, are you sure you checked the calling code and not the code that defines the function?
     
  7. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    1,085
    Did the GPS bug get fixed
     
  8. Mantas-Puida

    Mantas-Puida

    Joined:
    Nov 13, 2008
    Posts:
    1,864
    Yes, with Unity 4.0.1.