-1

first of all please don't judge me but i am trying to build a folium map with markers of all the McDonalds places in my country.
the first thing i did was downloading with webscraper all the nqmes and addresses of the places secondly i am trying to convert them with the geopy library to lat/lon points in order to load them into a folium marker

import folium
import pandas as pd
from geopy.geocoders import ArcGIS

snifim_df = pd.read_csv('Snif.csv')
nom = ArcGIS()
snifim_df['LAT'] = snifim_df['Address'].apply(nom.geocode).apply(lambda x:x.latitude) 
snifim_df['LON'] = snifim_df['Address'].apply(nom.geocode).apply(lambda x:x.longitude) 

my folium code will look like this

Mcmap = folium.Map(location=[35.58, -92.09], zoom_start = 6)
fg = folium.FeatureGroup(name = "McDonalds")

snif_lat = list(snifim_df['LAT'])
snif_lon = list(snifim_df['LON'])
snif_name = list(snifim_df['Name'])

for lat,lon, name in zip(snif_lat,snif_lon,snif_name):
    fg.add_child(folium.Marker(location=[lat,lon],popup=name))

Mcmap.add_child(fg)
Mcmap.save("test.html")

whenever i run this code one of two errors happen:
1) i get a geopy timeout error "geopy.exc.GeocoderTimedOut: Service timed out"
2) the code runs without an error but an html map does not appear in my folder

my dataset looks like this with 169 lines: enter image description here

can someone please save me and explain to me what is going wrong and how to fix it?
thanks in advance :)

michox2
  • 113
  • 11
  • How many locations you have to add in a map? – Sunnysinh Solanki Jan 10 '20 at 07:31
  • the total is 169 – michox2 Jan 10 '20 at 07:45
  • 169 locations are not that big. I suggest that you try to change the zoom level after the HTML file is saved when you open it in a browser. Also, check that you are actually passing correct latitude and longitude and both are not inversed. sometimes a minor mistake can take a toll. First, try yo get all latitude and longitude using geopy and save it into some CSV file. and then do the next step using CSV file so that you don't need to call geopy again and again. – Sunnysinh Solanki Jan 10 '20 at 07:47

1 Answers1

1

if you use folium 0.10.0, just test the code:

    snifim_df = pd.DataFrame({'name':['york', 'land', 'wu'], 'lat':[35.09,36.12,35.13],
                      'lon':[-90.18, -91.25, -90.88]}) 
    Mcmap = folium.Map(location=[35.58, -92.09], zoom_start = 6)
    fg = folium.FeatureGroup(name = "McDonalds")

    snif_lat = list(snifim_df['lat'])
    snif_lon = list(snifim_df['lon'])
    snif_name = list(snifim_df['name'])

    for lat,lon, name in zip(snif_lat,snif_lon,snif_name):
        fg.add_child(folium.Marker(location=[lat,lon],popup=name))

    Mcmap.add_child(fg)
    Mcmap.save("test.html")

then it's the result

enter image description here

H.Hao
  • 113
  • 1
  • 1
  • 10
  • I know how to do this the way you did but you made it manually, I can't do this manually to 169 locations – michox2 Jan 10 '20 at 08:21