import pgeocode
import folium

'''
Provide a Country code and postal code.
It will generate a map in a html file based on these details.
Used pgeocode and folium packages.
'''

def zipcode_to_map(country_code, postal_code):
country_code = pgeocode.Nominatim(country_code)

zip_code = country_code.query_postal_code(postal_code)

postal_code = zip_code['postal_code']
multiple_zip_codes = country_code.query_postal_code(["560034", "560083"])

m = folium.Map(location=[zip_code['latitude'], zip_code['longitude']], 
zoom_start=9,
                   detect_retina=True, control_scale=False)

m.save(f'{postal_code}-map.html')

zipcode_to_map('in','515411')

I wrote this function.You can use this function to generate map using a 
zipcode and countrycode. Hope it will be useful for you.

On Thursday, June 4, 2020 at 3:15:55 AM UTC+5:30, Ram wrote:
>
> Hi,
>
> We need to add location map based on the zip code in our DJango web 
> application. Is there any free API available out there? if you have used it 
> already could you suggest one?
>
> Thanks,
> ~Ram
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7b985c15-b523-497b-91a4-8b08586e7f28%40googlegroups.com.

Reply via email to