0

I am trying to find out the coordinates of various addresses located in NYC (NYPD precinct address), United States. However, the below code returns the coordinates for a place in South Africa (miles away from the US).

location = geolocator.geocode("2271-89 8th Avenue")
print((location.latitude, location.longitude))

My guess is geopy does not pick up this address as that in Manhattan, NYC. I got this address from New York Police's website.

Questions-

  1. How to specify which country or place the geopy should look?
  2. How does geopy pick one address if there are multiple places with the same address like above?
  3. How can I fix my issue?
wjandrea
  • 28,235
  • 9
  • 60
  • 81
  • IIRC, GeoPy doesn't do any of what you're asking about, it's entirely the geolocator service. Which one are you using? And are you open to switching? – wjandrea Nov 29 '22 at 00:19
  • How are you getting the addresses? If you're getting them manually, why not just add `", NYC, USA"` to any that don't have it? If you're scraping them, I suppose that'll be more difficult. – wjandrea Nov 29 '22 at 00:20
  • @wjandrea https://stackoverflow.com/questions/69854674/python-generate-lat-long-points-from-address this is the code i am referring to. I am getting the address from https://www.nyc.gov/site/nypd/bureaus/patrol/precincts-landing.page I just converted the table given here and used it as a csv after minor processing. So for precinct 28, the address gets converted to a lat, long which is in africa, how do I fix that? I tried suffixing the address with USA/NY/NYC,etc. but none of them works. In fact i get the following error- "AttributeError: 'NoneType' object has no attribute 'latitude'" – Rahul Ramaswamy Nov 29 '22 at 05:24
  • address used - "2271-89 8th Avenue, NYC, USA", actual address - "2271-89 8th Avenue" which shows coordinates in South Africa – Rahul Ramaswamy Nov 29 '22 at 05:31

0 Answers0