如何在R中使用诺基亚HERE API

如何在R中使用诺基亚HERE API,r,here-api,shapefile,R,Here Api,Shapefile,我正在尝试从Nokia HERE Enterprise API下载逆流等值线的坐标() 我能够运行查询,并获得一个很长的纬度+经度列表,但当我尝试创建和绘制一个空间多边形时,我发现点的顺序似乎是随机的。图表如下所示: my.coord.pairs谢谢斯科特·张伯伦,我同意你的看法,我的问题没有很好地组合起来 答案是我对逆流资源的理解是错误的。它不会像计算等值线资源那样返回多边形。此外,它现在是API的遗留资源 检索我想要的内容的正确方法是使用带有destination参数的计算等值线资源,而不是

我正在尝试从Nokia HERE Enterprise API下载逆流等值线的坐标()

我能够运行查询,并获得一个很长的纬度+经度列表,但当我尝试创建和绘制一个空间多边形时,我发现点的顺序似乎是随机的。图表如下所示:


my.coord.pairs谢谢斯科特·张伯伦,我同意你的看法,我的问题没有很好地组合起来

答案是我对逆流资源的理解是错误的。它不会像计算等值线资源那样返回多边形。此外,它现在是API的遗留资源

检索我想要的内容的正确方法是使用带有destination参数的计算等值线资源,而不是start争论

API文档中没有注意到计算等值线资源的这一双重功能(目的地/起点),尽管如此,它仍然可以正常工作:

下面是我的一段代码,它向“计算等值线”资源发出请求,然后解压缩返回的数据以获得多边形(即形成多边形的点列表)。请注意,该代码需要一个应用程序ID和应用程序代码,这是您在创建HERE API帐户时获得的

# These variables below are just to compose the example code.
latitude <- 34.9859619
longitude <- -78.5900116
range <- 1800 # 30 minutes, in seconds
resolution <- 5

# Now comes the real code
response_parsed <- RJSONIO::fromJSON(RCurl::getURL(paste0("http://isoline.route.cit.api.here.com/routing/7.2/calculateisoline.json",
"?app_id=", App_id, "&app_code=", App_code, "&range=", range, "&rangetype=time", "&destination=geo!", latitude, ",",
longitude, "&mode=fastest;car;traffic:enabled")))

if(length(response_parsed) == 0)
  stop('Error in JSON request.')

polygon <- data.frame(long=numeric, lat=numeric)

# The points (latitude+longitude) come together as characters separated by a comma. We need to split them.
for(rsh in response_parsed$response$isoline[[1]]$component[[1]]$shape) {
  split <- strsplit(rsh, ",")[[1]]
  polygon <- rbind(polygon, data.frame(long=as.numeric(split[[2]]), lat=as.numeric(split[[1]])))
}
# Now the polygon data frame contains all points that form the polygon returned by Calculate Isoline.
#下面的这些变量只是为了组成示例代码。

纬度不是一个可再现的例子,至少包括虚拟数据,以允许我们再现问题
# These variables below are just to compose the example code.
latitude <- 34.9859619
longitude <- -78.5900116
range <- 1800 # 30 minutes, in seconds
resolution <- 5

# Now comes the real code
response_parsed <- RJSONIO::fromJSON(RCurl::getURL(paste0("http://isoline.route.cit.api.here.com/routing/7.2/calculateisoline.json",
"?app_id=", App_id, "&app_code=", App_code, "&range=", range, "&rangetype=time", "&destination=geo!", latitude, ",",
longitude, "&mode=fastest;car;traffic:enabled")))

if(length(response_parsed) == 0)
  stop('Error in JSON request.')

polygon <- data.frame(long=numeric, lat=numeric)

# The points (latitude+longitude) come together as characters separated by a comma. We need to split them.
for(rsh in response_parsed$response$isoline[[1]]$component[[1]]$shape) {
  split <- strsplit(rsh, ",")[[1]]
  polygon <- rbind(polygon, data.frame(long=as.numeric(split[[2]]), lat=as.numeric(split[[1]])))
}
# Now the polygon data frame contains all points that form the polygon returned by Calculate Isoline.