Skip to content
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

wrong S2 cell ID for given latitude and longitude #48

Open
adrianomitre opened this issue Jul 17, 2017 · 2 comments
Open

wrong S2 cell ID for given latitude and longitude #48

adrianomitre opened this issue Jul 17, 2017 · 2 comments

Comments

@adrianomitre
Copy link

adrianomitre commented Jul 17, 2017

(main)> require 'poke-api'
=> true
(main)> lat = -23.59260639636282
=> -23.59260639636282
(main)> lng = -46.680191904206524
=> -46.680191904206524
(main)> Poke::API::Helpers.get_cells(lat, lng)
=> [
    [ 0] 10722603741376151552,
    [ 1] 10722603743523635200,
    [ 2] 10722603745671118848,
    [ 3] 10722603747818602496,
    [ 4] 10722603749966086144,
    [ 5] 10722603752113569792,
    [ 6] 10722603754261053440,
    [ 7] 10722603756408537088,
    [ 8] 10722603758556020736,
    [ 9] 10722603760703504384,
    [10] 10722603762850988032,
    [11] 10722603764998471680,
    [12] 10722603767145955328,
    [13] 10722603769293438976,
    [14] 10722603771440922624,
    [15] 10722603773588406272,
    [16] 10722603775735889920,
    [17] 10722603777883373568,
    [18] 10722603780030857216,
    [19] 10722603782178340864,
    [20] 10722603784325824512
]

which does not contain the S2 Cell ID 10722603763924729856, whose center is lat, lng.

Contrast this with sidewalklabs/s2sphere: Python implementation of the S2 geometry library:

>>> import s2sphere
>>> lat = -23.59260639636282
>>> lng = -46.680191904206524
>>> cell = s2sphere.Cell.from_lat_lng(s2sphere.LatLng.from_degrees(lat, lng))
>>> cell.id().parent(12).id()
10722603763924729856
@adrianomitre adrianomitre changed the title wrong S2 cell ID BUG: wrong S2 cell ID for given latitude and longitude Jul 18, 2017
@adrianomitre adrianomitre changed the title BUG: wrong S2 cell ID for given latitude and longitude wrong S2 cell ID for given latitude and longitude Jul 18, 2017
@nabeelamjad
Copy link
Owner

nabeelamjad commented Jul 18, 2017

Good find, unfortunately I don't think I've got the time now to debug this as this project has been deprecated since almost a year ago and I'm quite busy these days.

The S2 implementation was a quick conversion of some functionality to make it work for calculating cells in use with Pokemon Go, during the conversion it appeared to work fine (as in I had values that were the same as s2sphere from Python, granted there's no test suite or anything for this project).

I'd probably refer to people using an actual port or native binding of Google's S2 Geometry for the full functionality, though I don't think one exists for Ruby (which is why I had to throw something together).

@adrianomitre
Copy link
Author

adrianomitre commented Jul 19, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants