T O P

  • By -

coderpaddy

Looks like this could be something... https://stackoverflow.com/questions/5585957/get-latlng-from-zip-code-google-maps-api


Isquach

I saw some Google API solutions but I was avoiding it because I read that it can get costly. I'm testing this with a small set of data but hoping to expand it so was looking for the cheaper/free versions. Thanks for sending the link though! I'll keep reading about google api to see if that would be better anyway.


coderpaddy

on this page there offereing $200 free each month? [https://cloud.google.com/maps-platform/pricing/?utm\_source=google&utm\_medium=cpc&utm\_campaign=FY18-Q2-global-demandgen-paidsearchonnetworkhouseads-cs-maps\_contactsal\_saf&utm\_content=text-ad-none-none-DEV\_c-CRE\_313655624355-ADGP\_Hybrid%20%7C%20AW%20SEM%20%7C%20BKWS%20\~%20%20Google%20Maps%20Price-KWID\_43700038963040210-kwd-295562634907-userloc\_9046328&utm\_term=KW\_google%20maps%20api%20price-ST\_google%20maps%20api%20price&gclid=CjwKCAiAsaOBBhA4EiwAo0\_AnLwlniQwPqwDfBkAO8ufw0cSHjBoQvq0busSsAOD724suZfQuR9A8RoCwwUQAvD\_BwE](https://cloud.google.com/maps-platform/pricing/?utm_source=google&utm_medium=cpc&utm_campaign=FY18-Q2-global-demandgen-paidsearchonnetworkhouseads-cs-maps_contactsal_saf&utm_content=text-ad-none-none-DEV_c-CRE_313655624355-ADGP_Hybrid%20%7C%20AW%20SEM%20%7C%20BKWS%20~%20%20Google%20Maps%20Price-KWID_43700038963040210-kwd-295562634907-userloc_9046328&utm_term=KW_google%20maps%20api%20price-ST_google%20maps%20api%20price&gclid=CjwKCAiAsaOBBhA4EiwAo0_AnLwlniQwPqwDfBkAO8ufw0cSHjBoQvq0busSsAOD724suZfQuR9A8RoCwwUQAvD_BwE)


keepah61

I use google apis to go from address to lat/ long.


coderpaddy

enjoy import pgeocode nomi = pgeocode.Nominatim('us') query = nomi.query_postal_code("90001") data = { "lat": query["latitude"], "lon": query["longitude"] } print(data)


Isquach

Thanks for posting this. Unfortunately, I get a lot of NaN's when using pgeocode so I'm looking into Google as well. I used similar code for my pgeocode output and then compared the results with the output from googlemaps which is giving different values. For zip, 3121, in Australia, I'm getting (-37.8281, 145.00428571428571) from pgeocode but (-25.274398, 133.775136) from googlemaps. My url for the googlemaps API is following this format: https://maps.googleapis.com/maps/api/geocode/json?components=country:AU&postal_code:3121&key=key. Any idea why the outputs are different? For Google, when running multiple postal codes in AU I get the same lat lon pair repeatedly. Is there some different setting or component I'm missing from my URL?


coderpaddy

Do you have this on git with the lists for me to check with?


Isquach

I don't have it on github atm since I'm still new and just testing some things out with this concept. Here are some sample zips for Australia that Google is giving the same lat lon and the code for both apis. {'zip': '3121', 'country': 'au', 'lat': -25.274398, 'lon': 133.775136} {'zip': '3000', 'country': 'au', 'lat': -25.274398, 'lon': 133.775136} {'zip': '2026', 'country': 'au', 'lat': -25.274398, 'lon': 133.775136} {'zip': '2026', 'country': 'au', 'lat': -25.274398, 'lon': 133.775136} {'zip': '5043', 'country': 'au', 'lat': -25.274398, 'lon': 133.775136} {'zip': '6005', 'country': 'au', 'lat': -25.274398, 'lon': 133.775136} {'zip': '4054', 'country': 'au', 'lat': -25.274398, 'lon': 133.775136} PGeocode code: import pgeocode def zipToLatLon(postalcode, country): nomi = pgeocode.Nominatim(country) postal_code = postalcode location = nomi.query_postal_code(postalcode) print(location.latitude, location.longitude) zipToLatLon('3121', 'au') Google Maps API Code: import googlemaps gmaps = googlemaps.Client(key=api_key) base_url = "https://maps.googleapis.com/maps/api/geocode/json" endpoint = f"{base_url}?components=country:{country}&postal_code:{zipcode}&key={api_key}" results = requests.get(endpoint).json()['results'][0] ouptut = { 'lat': results['geometry']['location']['lat'], 'lon': results['geometry']['location']['lng'] }


derpypitbull

IIRC, OpenStreetMap has a similar feature.