Skip to content

Fix for different geolocation timestamp for Android and iOS #6150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Fix for different geolocation timestamp for Android and iOS #6150

wants to merge 1 commit into from

Conversation

gasperz
Copy link
Contributor

@gasperz gasperz commented Feb 25, 2016

Geolocation timestamp is different for Android and iOs. For Android it is returning in UTC time in milliseconds since January 1, 1970, for iOS it was returned as time interval relative to an absolute reference date (00:00:00 UTC on 1 January 2001). Also for iOS time returned was "current system absolute time" and not the time at which this location was determined.

Tested with 0.21.0-rc React Native. Init project with this additional code:
constructor(props) {super(props); navigator.geolocation.getCurrentPosition( (position) => { let initialPosition = JSON.stringify(position); console.log(position.timestamp); }, (error) => alert(error.message), {enableHighAccuracy: true, timeout: 20000, maximumAge: 1000} ); }

Tested with iOs simulator (iPhone 6S plus 9.2; iPhone 5s 8.4 )

sample result with change: 1456407795021.235
sample result without change: 23478100615007.884

Explaining links for iOS:
https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocation_Class/index.html#//apple_ref/occ/instp/CLLocation/timestamp
https://developer.apple.com/library/prerelease/ios/documentation/CoreFoundation/Reference/CFTimeUtils/index.html#//apple_ref/c/func/CFAbsoluteTimeGetCurrent
https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/index.html#//apple_ref/swift/cl/c:objc%28cs%29NSDate

Link for Android:
http://developer.android.com/reference/android/location/Location.html#getTime%28%29

Timestamp is different for Android and iOs. For Android it is returning in UTC time in milliseconds since January 1, 1970, for iOS it was returned as time interval relative to an absolute reference date (00:00:00 UTC on 1 January 2001). Also for iOS time returned was "current system absolute time" and not the time at which this location was determined.

Links for iOS: 
https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocation_Class/index.html#//apple_ref/occ/instp/CLLocation/timestamp
https://developer.apple.com/library/prerelease/ios/documentation/CoreFoundation/Reference/CFTimeUtils/index.html#//apple_ref/c/func/CFAbsoluteTimeGetCurrent
https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/index.html#//apple_ref/swift/cl/c:objc%28cs%29NSDate

Link for Android:
http://developer.android.com/reference/android/location/Location.html#getTime%28%29
@facebook-github-bot
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @nicklockwood, @brentvatne and @zjj010104 to be potential reviewers.

@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at [email protected]. Thanks!

@satya164
Copy link
Contributor

cc @nicklockwood

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 25, 2016
@nicklockwood
Copy link
Contributor

Oh wow, that's terrible. Thanks for the fix.

@facebook-github-bot shipit

@facebook-github-bot
Copy link
Contributor

Thanks for importing. If you are an FB employee go to Phabricator to review.

@ghost ghost closed this in 13f2aea Feb 25, 2016
pglotov pushed a commit to pglotov/react-native that referenced this pull request Mar 15, 2016
Summary:Geolocation timestamp is different for Android and iOs. For Android it is returning in UTC time in milliseconds since January 1, 1970, for iOS it was returned as time interval relative to an absolute reference date (00:00:00 UTC on 1 January 2001). Also for iOS time returned was "current system absolute time" and not the time at which this location was determined.

Tested with 0.21.0-rc React Native. Init project with this additional code:
`constructor(props) {super(props);
    navigator.geolocation.getCurrentPosition(
      (position) => {
        let initialPosition = JSON.stringify(position);
        console.log(position.timestamp);
      },
      (error) => alert(error.message),
      {enableHighAccuracy: true, timeout: 20000, maximumAge: 1000} );
  }
`

Tested with iOs simulator (iPhone 6S plus 9.2; iPhone 5s 8.4 )

sample result with change: 1456407795021.235
sample result without change: 23478100615007.884

Explaining links for iOS:
https://developer.apple.com/library/ios/do
Closes facebook#6150

Differential Revision: D2976909

Pulled By: nicklockwood

fb-gh-sync-id: 9607ed669d7200591f8387e4186cf7c225ae9b3a
shipit-source-id: 9607ed669d7200591f8387e4186cf7c225ae9b3a
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Platform: iOS iOS applications.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants