1

How to get the latitude and longitude of a tweet using the Twitter gem?

Raj
  • 22,346
  • 14
  • 99
  • 142
nadine1988
  • 167
  • 2
  • 10

1 Answers1

1

took me a while to get my head around but like this:

Twitter.status(227376948400230400).place.bounding_box.coordinates

hope this helps.

Simon
  • 375
  • 5
  • 12
  • Is "227376948400230400" the id of a tweet? – nadine1988 Jul 23 '12 at 13:10
  • Yes that's the ID of a tweet I posted but you can change this to for example user_timeline(username).first which would be a users last tweet. – Simon Jul 23 '12 at 13:18
  • Like this? Twitter.status.user_timeline("username").first.place.bounding_box.coordinates – nadine1988 Jul 23 '12 at 13:31
  • It doesn't work: `
    ': undefined method `bounding_box' for nil:NilClass (NoMethodError)
    – nadine1988 Jul 23 '12 at 13:54
  • that tweet doesn't have a place set. Just did some testing if you don't set a location on the tweet .place will return nil making the rest fail. – Simon Jul 23 '12 at 14:09