包的github下載地址:https://github.com/badbye/baidumap
一.安裝方式:
可見(jiàn)作者關(guān)于安裝的文章
二.使用方法:
- getbaidumap函數(shù):
getBaiduMap(location, width = 400, height = 400, zoom = 10, scale = 2, color = "color", messaging = TRUE)
參數(shù):
location:包含經(jīng)度和維度的向量或者是一個(gè)矩陣,或者可以是一個(gè)字符串表示地址;經(jīng)緯度和地址將作為地圖的中心點(diǎn)
width,height:map的寬和高
zoom:map的縮放比例,是一個(gè)整數(shù),從3(洲)到21(building),默認(rèn)值是10
scale:像素?cái)?shù)
color:"color" or "bw",表示有色或者是黑白
messaging:邏輯語(yǔ)句,決定是否輸出下載數(shù)據(jù)的信息
- getCoordinate函數(shù):根據(jù)地址得到經(jīng)緯度(比較常用):
getCoordinate(address, city = NULL, output = "json", formatted = F)
參數(shù):
address:地址
city:可選項(xiàng),地質(zhì)所在的城市
output:json或者xml格式
formatted:F返回原有的json或者xml格式,而T返回的是經(jīng)緯度的矩陣
例子:
getCoordinate('同濟(jì)科技廣場(chǎng)',output = 'xml')#xml
同濟(jì)科技廣場(chǎng)
"<?xml version="1.0" encoding="utf-8"?>\n<GeocoderSearchResponse>\n\t<status>0</status>\n\t<result>\n\t\t<location>\n\t\t\t<lng>120.339932776</lng>\n\t\t\t<lat>36.0885120359</lat>\n\t\t</location>\n\t\t<precise>1</precise>\n\t\t<confidence>80</confidence>\n\t\t<level>UNKNOWN</level>\n\t</result>\n</GeocoderSearchResponse>\n\n"
getCoordinate('同濟(jì)科技廣場(chǎng)',output = 'json')
同濟(jì)科技廣場(chǎng)
"{"status":0,"result":{"location":{"lng":120.33993277617836,"lat":36.08851203594274},"precise":1,"confidence":80,"level":"UNKNOWN"}}"
getCoordinate(c('同濟(jì)科技廣場(chǎng)','常熟理工東南校區(qū)','常熟理工東湖校區(qū)'),formatted = T)
longtitude latitude
同濟(jì)科技廣場(chǎng) 120.3399328 36.08851204
常熟理工東南校區(qū) 120.8314860 31.66944605
常熟理工東湖校區(qū) 115.9101483 28.69237515
- getLocation:通過(guò)經(jīng)緯度得到地址
location:經(jīng)緯度
output:json或者xml格式
formatted:是否返回一個(gè)較好的結(jié)果
pois:是否返回這個(gè)位置周?chē)腜IO
loc =
matrix(c(115.183148,39.629221,117.151659,39.955654,116.746918,39.358383), byrow=T, ncol=2)location = getLocation(loc, formatted = T)
location
lon=115.183148;lat=39.629221 lon=117.151659;lat=39.955654 lon=116.746918;lat=39.358383
"河北省保定市淶水縣" "河北省廊坊市三河市黃閩路" "河北省廊坊市安次區(qū)S272(廊崔線)"
- getPlace函數(shù):返回地圖搜索結(jié)果
getPlace(place = NULL, city = "北京")
參數(shù):
place:你想要搜索的地方
city:城市
返回值:數(shù)據(jù)框dataframe:包含名字、經(jīng)緯度、地址等
js_college<-getPlace('餐廳','常熟')
Get 400 records, 20 page.
Getting 0 th page
Getting 1 th page
Getting 2 th page
Getting 3 th page
Getting 4 th page
Getting 5 th page
Getting 6 th page
Getting 7 th page
Getting 8 th page
Getting 9 th page
Getting 10 th page
Getting 11 th page
Getting 12 th page
Getting 13 th page
Getting 14 th page
Getting 15 th page
Getting 16 th page
Getting 17 th page
Getting 18 th page
Getting 19 th page
Getting 20 th page
Done!
head(js_college)
name address lat lon
1 渡口飯店(1號(hào)店) 江蘇省蘇州市常熟市興港路 31.725805 121.055062
2 王四酒家 虞山北路358號(hào)(近常熟國(guó)際飯店) 31.675453 120.735216
3 肯德基(梅李餐廳店) 梅李鎮(zhèn)通江路11號(hào)銀河苑1區(qū)5幢123-124號(hào)一二層 31.714455 120.880523
4 幸福小灶飯店 近郊珠江路99號(hào)(王梓樓足浴旁) 31.668996 120.773694
5 金海華常熟總店 蘇州近郊常熟市方塔街83號(hào)近蘇苑街近蘇寧電器 31.649494 120.747700
6 大方圓酒家(新顏東路店) 蘇州近郊常熟市新顏東路58號(hào) 31.649959 120.778824
telephone
1 (0512)52646608,13706239111
2 (0512)52849999,(0512)52849777
3 4008828823
4 (0512)52032866
5 (0512)52788888,(0512)5270 2333
6 (0512)52999997
- getRoute函數(shù):通過(guò)搜索得到路線
getRoute(...)
參數(shù):
origin:起點(diǎn)
destination:終點(diǎn)
mode:出行方式,'walk','transit'
region:起點(diǎn)和終點(diǎn)所在區(qū)域,若不在同一地區(qū),分別用origin_region和destination_region
tactics:10(不走高速), 11(默認(rèn), 最短時(shí)間), 12(最短路徑).
coord_type:'bd09ll'(default), 'gcj02'(which Google map and Soso map are using), 'wgs84' for GPS devices.
返回值:dataframe:包含經(jīng)緯度
route<-getRoute('常熟理工東南校區(qū)','常熟理工東湖校區(qū)')
head(route)
lon lat
1 120.7844034 31.59385505
2 120.7846135 31.59396463
3 120.7846635 31.59412457
4 120.7846635 31.59412457
5 120.7833428 31.59547797
6 120.7832628 31.59557824