在地图上绘制纬度/经度附近的时间半径 [英] Draw time radius around lat/long on map
问题描述
我正在使用R中的gmapsdistance
程序包.我有我的API密钥,并且我熟悉该程序包中的功能.
I am working with the gmapsdistance
package in R. I have my API key, and I am familiar with the functions within the package.
但是,我想反方向解决一个问题.我不只是查找经/纬度之间的Time
,Distance
和Status
是经/纬度的向量,我想输入纬度/经度,并绘制所有可以驱动到的点的区域在3小时以内.然后,我想在Google地图上绘制它.
首先,最好使用佛罗里达州马里马尔(Marimar):25.9840,-802.2821.
However, I would like to work out a problem in the reverse direction. Instead of just finding the Time
, Distance
, and Status
between lat/longs are vectors of lat/longs, I would like to input a lat/long, and draw a region of all points that could be driven to in 3 hours or less. Then I'd like to draw this on a Google map.
To start, it would be great to use Marimar, FL: 25.9840, -80.2821.
有人有处理这类问题的经验吗?
Does anyone have experience with that type of problem?
推荐答案
As suggested in the comments, you can sign up to a service like Travel Time Platform (which I'm using in this example) and use their API to get the possible destinations given a starting point.
然后,您可以使用Google Maps(在我的googleway软件包中)在地图上绘制该图
Then you can plot this on a map using Google Maps (in my googleway package)
appId <- "TravelTime_APP_ID"
apiKey <- "TravelTime_API_KEY"
mapKey <- "GOOGLE_MAPS_API_KEY"
library(httr)
library(googleway)
library(jsonlite)
location <- c(25.9840, -80.2821)
driveTime <- 2 * 60 * 60
## London example
## location <- c(51.507609, -0.128315)
## sign up to http://www.traveltimeplatform.com/ and get an API key
## and use their 'Time Map' API
url <- "http://api.traveltimeapp.com/v4/time-map"
requestBody <- paste0('{
"departure_searches" : [
{"id" : "test",
"coords": {"lat":', location[1], ', "lng":', location[2],' },
"transportation" : {"type" : "driving"} ,
"travel_time" : ', driveTime, ',
"departure_time" : "2017-05-03T08:00:00z"
}
]
}')
res <- httr::POST(url = url,
httr::add_headers('Content-Type' = 'application/json'),
httr::add_headers('Accept' = 'application/json'),
httr::add_headers('X-Application-Id' = appId),
httr::add_headers('X-Api-Key' = apiKey),
body = requestBody,
encode = "json")
res <- jsonlite::fromJSON(as.character(res))
pl <- lapply(res$results$shapes[[1]]$shell, function(x){
googleway::encode_pl(lat = x[['lat']], lon = x[['lng']])
})
df <- data.frame(polyline = unlist(pl))
df_marker <- data.frame(lat = location[1], lon = location[2])
google_map(key = mapKey) %>%
add_markers(data = df_marker) %>%
add_polylines(data = df, polyline = "polyline")
这篇关于在地图上绘制纬度/经度附近的时间半径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!