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

Obtaining cell_ids #2

Closed
selivandex opened this issue Jul 23, 2016 · 9 comments
Closed

Obtaining cell_ids #2

selivandex opened this issue Jul 23, 2016 · 9 comments

Comments

@selivandex
Copy link

Hello, can you say how did you generated cell_id in the exmaple.rb ? And what cell_id we need?

@selivandex
Copy link
Author

As i understand cell id you used in example.rb is only for New York

@nabeelamjad
Copy link
Owner

The example cell ID was generated by using the S2 geometry in Python's interpreter, unfortunately the library in question does not exist in Ruby (yet). I am looking for a way to get this implemented but unsure how long that will take.

If you need cell_ids then I'd suggest to have a look at this Python excerpt: https://github.com/tejado/pgoapi/blob/master/pokecli.py#L63 (the methods are imported from using s2sphere library which is Python's S2 Geometry lib.

@nabeelamjad nabeelamjad added bug and removed bug labels Jul 23, 2016
@selivandex
Copy link
Author

I've wrote code like this https://gist.github.com/selivandex/35d2e08de01a1aae59bbd261db40af0a

And here is ruby usage cell_ids = %x(python #{Rails.root.join('lib', 'get_cell_id.py')} -lat #{client.lat} -lng #{client.lng})

But i getting response array of cell ids

[2401181244772581376L, 2401181246920065024L]

Can you help me understand? What is L at the end of each id ?

@nabeelamjad
Copy link
Owner

nabeelamjad commented Jul 23, 2016

L stands for Long in Python, it's just to indicate the type of the integer really (you don't see this in Python 3+ anymore)

You could use something like this:

  • This is all assuming you have Python installed and invokable by calling python (if you do have it installed but calling python does not invoke it then you need to set up your PATH correctly to include python).

example.rb

require 'poke-api'
require 'pp'

client = Poke::API::Client.new

client.store_location('New York')
client.login('username', 'password', 'ptc')

# Replace this line as you wish to call the right library, if your file is in a folder ``lib``
# and the example is in the parent directory then you could call from lib.get_cell_id
# A third argument can be optionally provided to indicate the radius (in this case 15)
cell_ids = `python -c 'from get_cell_id import get_cell_ids; \
            print(get_cell_ids(#{client.lat},#{client.lng}, 15))'`
cell_ids = cell_ids.tr('[L]', '').split.map(&:to_i)

client.get_map_objects(
  latitude: client.lat,
  longitude: client.lng,
  since_timestamp_ms: [0] * cell_ids.length,
  cell_id: cell_ids
)

pp client.call

get_cell_id.py (requires s2sphere library to be installed for Python -> pip install s2sphere)

from s2sphere import CellId, LatLng

def get_cell_ids(lat, long, radius = 10):
    origin = CellId.from_lat_lng(LatLng.from_degrees(lat, long)).parent(15)
    walk = [origin.id()]
    right = origin.next()
    left = origin.prev()
    for i in range(radius):
        walk.append(right.id())
        walk.append(left.id())
        right = right.next()
        left = left.prev()
    return sorted(walk)

You get the idea :)

@nabeelamjad nabeelamjad changed the title Cell id Obtaining cell_ids Jul 23, 2016
@nabeelamjad
Copy link
Owner

As of the latest protobufs update both client.lat and client.long will once again return a double so they can directly be entered into the python function, I've updated the previous post to reflect this.

@nabeelamjad
Copy link
Owner

Will implement this tomorrow in native Ruby (just enough so we can use it to generate S2 cells).

@xssc
Copy link
Contributor

xssc commented Aug 6, 2016

@nabeelamjad Thanks!

@nabeelamjad
Copy link
Owner

I've put up a PR #28 just to ensure that the work I've done is right and if anything needs to be changed, I'll probably merge it in tomorrow.

@nabeelamjad
Copy link
Owner

nabeelamjad commented Aug 7, 2016

I've merged in S2 Geometry cells in the latest release, I'll separate the repo at some other point when I have more time.

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

Successfully merging a pull request may close this issue.

3 participants