-1

Hello I have the following json file with information about 6.000 restaurants in Las Vegas such as: "name" , "longitude" ,"latitude" .I want to create a map and map pin labels using the "longitude" ,"latitude" of each point and to display the "name" of each restaurant in a map.I use pycharm and python 3.6.5(32 bit).I try to import folium library,it works, but it does not display the name of each restaurant in the map.How can I dispaly the name of each restaurant in a map?Thanks in advance!

The json file yelp_restaurant_Las_Vegas is:

{ 
"_id" : ObjectId("5a9eb7b2a2f96c346024f239"), 
"city" : "Las Vegas", 
"neighborhood" : "Southeast", 
"name" : "Flight Deck Bar & Grill", 
"business_id" : "Pd52CjgyEU3Rb8co6QfTPw", 
"longitude" : -115.1708484, 
"hours" : {
    "Monday" : "8:30-22:30", 
    "Tuesday" : "8:30-22:30", 
    "Friday" : "8:30-22:30", 
    "Wednesday" : "8:30-22:30", 
    "Thursday" : "8:30-22:30", 
    "Sunday" : "8:30-22:30", 
    "Saturday" : "8:30-22:30"
}, 
"state" : "NV", 
"postal_code" : "89119", 
"categories" : [
    "Nightlife", 
    "Bars", 
    "Barbeque", 
    "Sports Bars", 
    "American (New)", 
    "Restaurants"
], 
"stars" : 4.0, 
"address" : "6730 S Las Vegas Blvd", 
"latitude" : 36.0669136, 
"review_count" : NumberInt(13), 
"is_open" : NumberInt(1), 
  .
  .
  .

The code is:

from pymongo import MongoClient
import pandas as pd
import folium
from IPython.display import HTML
client = MongoClient("localhost",27017)

db = client.Desktop
collection1 =db.yelp_restaurant_Las_Vegas
reviews=pd.DataFrame(list(collection1.find()))


mapi_osm = folium.Map(location=())
reviews.apply(lambda row:folium.CircleMarker(location[row["latitude"],row["longitude"]]).add_to(mapi_osm),axis=1)

mapi_osm.save('spst.html')
katios
  • 11
  • 2

1 Answers1

0

Add Popups to your markers.

If you want them auto-opened, you'll need the latest folium from github (as the version on pypi isn't new enough). Support for leaflet's openPopup call via the show parameter was added a couple of weeks ago. If you don't care about them being auto-opened then doesn't matter (just get rid of the show parameter of the Popup constructor).

pip install git+https://github.com/python-visualization/folium.git
reviews.apply(lambda row:folium.CircleMarker(
          location=[row["latitude"],row["longitude"]],
          popup=Popup(row['name'],show=True)).add_to(mapi_osm),axis=1)

Here's a minimal example:

import folium
from folium.map import Popup

m = folium.Map(location=())
folium.CircleMarker(location=(36.112625, -115.176704), popup=Popup('Picasso', show=True)).add_to(m)
m.save('map.html')
clockwatcher
  • 3,193
  • 13
  • 13