您好,我有以下json文件,其中包含有关拉斯维加斯6.000家餐厅的信息,例如:"名称","经度","纬度"。我想使用每个点的"经度","纬度"创建地图和地图图钉标签,并在地图上显示每个餐厅的"名称"。我使用 pycharm 和 python 3.6.5(32 位(。我尝试导入folium库,它可以工作,但它没有在地图上显示每个餐厅的名称。如何在地图上显示每家餐厅的名称?提前感谢!
yelp_restaurant_Las_Vegas的 json 文件为:
{
"_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),
.
.
.
代码为:
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')
将弹出窗口添加到您的标记中。
如果你想让它们自动打开,你需要来自 github 的最新叶子(因为 pypi 上的版本还不够新(。 几周前添加了通过 show 参数对传单的 openPopup 调用的支持。 如果您不关心它们是否自动打开,那么没关系(只需摆脱 Popup 构造函数的 show 参数(。
pip install git+https://github.com/python-visualization/folium.git
reviews.apply(lambda row:folium.圆标记( 位置=[行["纬度"],行["经度"]], popup=Popup(row['name'],show=True((.add_to(mapi_osm(,axis=1(
下面是一个最小的例子:
进口叶子 从folium.map导入弹出窗口 m = 叶子。地图(位置=((( 叶。CircleMarker(location=(36.112625, -115.176704(, popup=Popup('Picasso', show=True((.add_to(m( m.save('map.html'(