Skip to content

Commit

Permalink
update example to show US state
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Penman authored and Richard Penman committed Jun 6, 2024
1 parent 8032ea9 commit 33da370
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ Example usage:

```
>>> import reverse_geocode
>>> coordinates = (-37.81, 144.96), (31.76, 35.21)
>>> reverse_geocode.search(coordinates)
>>> melbourne_coord = -37.81, 144.96
>>> reverse_geocode.get(melbourne_coord)
{'city': 'Melbourne', 'country_code': 'AU', 'country': 'Australia', 'state': 'Victoria'}
>>> nyc_coord = 40.71427000, -74.00597000
>>> reverse_geocode.search((melbourne_coord, nyc_coord))
[{'city': 'Melbourne', 'country_code': 'AU', 'country': 'Australia', 'state': 'Victoria'},
{'city': 'Jerusalem', 'country_code': 'IL', 'country': 'Israel', 'state': 'Jerusalem'}]
{'city': 'New York City', 'country_code': 'US', 'country': 'United States', 'state': 'New York'}]
```

The module has a set of known geocoded locations and uses a [k-d tree](http://en.wikipedia.org/wiki/K-d_tree>) to efficiently find the nearest neighbour. This can be useful when you need to reverse geocode a large number of coordinates so a web API is not practical.
Expand Down
2 changes: 1 addition & 1 deletion reverse_geocode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,6 @@ def search(coordinates):
if __name__ == "__main__":
# test some coordinate lookups
city1 = -37.81, 144.96
city2 = 31.76, 35.21
city2 = 40.71427000, -74.00597000
print(get(city1))
print(search([city1, city2]))
4 changes: 2 additions & 2 deletions test_reverse_geocode.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

class TestBuiltwith(unittest.TestCase):
def test_wordpress(self):
coordinates = (-37.81, 144.96), (31.76, 35.21)
coordinates = (-37.81, 144.96), (40.71427000, -74.00597000)
results = reverse_geocode.search(coordinates)
self.assertEqual(
results,
[
{"city": "Melbourne", "country_code": "AU", "country": "Australia", "state": "Victoria"},
{"city": "Jerusalem", "country_code": "IL", "country": "Israel", "state": "Jerusalem"},
{"city": "New York City", "country_code": "US", "country": "United States", "state": "New York"},
],
)

Expand Down

0 comments on commit 33da370

Please sign in to comment.