poke-api icon indicating copy to clipboard operation
poke-api copied to clipboard

wrong S2 cell ID for given latitude and longitude

Open adrianomitre opened this issue 7 years ago • 2 comments

(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 avatar Jul 17 '17 23:07 adrianomitre

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).

nabeelamjad avatar Jul 18 '17 00:07 nabeelamjad

So maybe a warning on related source files and/or README would suffice...

Em seg, 17 de jul de 2017 às 21:56, nabeelamjad [email protected] escreveu:

Good find, unfortunately I don't think I've got the time now to debug this as this project has been deprecated since almost one 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.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/nabeelamjad/poke-api/issues/48#issuecomment-315926978, or mute the thread https://github.com/notifications/unsubscribe-auth/AAb4ZFWg6uovdUDymgEYts-O_IV0uO5Qks5sPAKzgaJpZM4OaqaR .

-- Adriano Mitre

adrianomitre avatar Jul 19 '17 00:07 adrianomitre