Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R:获取一个国家的经度和纬度_R_Shiny_Leaflet - Fatal编程技术网

R:获取一个国家的经度和纬度

R:获取一个国家的经度和纬度,r,shiny,leaflet,R,Shiny,Leaflet,我想得到一个特定国家的经度和纬度,这样我就可以在地图上缩放到那个国家。我正在使用shiny中的传单。我知道我可以使用“设置视图(经度、纬度、缩放=4)”。但是我如何得到这个国家的经纬度呢 到目前为止,我已经编写了以下代码: library(shiny) library(leaflet) ui <- fluidPage( leafletOutput("CountryMap", width = 1000, height = 500) ) server <- function(

我想得到一个特定国家的经度和纬度,这样我就可以在地图上缩放到那个国家。我正在使用shiny中的传单。我知道我可以使用“设置视图(经度、纬度、缩放=4)”。但是我如何得到这个国家的经纬度呢

到目前为止,我已经编写了以下代码:

library(shiny)
library(leaflet)

ui <- fluidPage(

   leafletOutput("CountryMap", width = 1000, height = 500)
)

server <- function(input, output){

   Country = map("world", fill = TRUE, plot = FALSE, regions="USA")
   output$CountryMap <- renderLeaflet({

  leaflet(Country) %>% addTiles() %>%  setView( 0 , 0, zoom = 4)%>%
   addPolygons(fillOpacity = 0.6,  smoothFactor = 0.5, stroke = TRUE, weight = 1)
})
}


shinyApp(ui =ui, server = server)
库(闪亮)
图书馆(单张)
ui%
addPolygons(fillOpacity=0.6,smoothFactor=0.5,stroke=TRUE,weight=1)
})
}
shinyApp(用户界面=用户界面,服务器=服务器)

我想放大到一个国家。所以我找到了更好的方法。使用fitBounds(映射、lng1、lat1、lng2、lat2)

代码如下:

library(shiny)
library(leaflet)
library(maps)

ui <- fluidPage(

  leafletOutput("CountryMap", width = 1000, height = 500)
)

server <- function(input, output){

 Country = map("world", fill = TRUE, plot = FALSE, regions="USA", exact=TRUE)
 output$CountryMap <- renderLeaflet({
     leaflet(Country) %>% addTiles() %>%
     fitBounds(Country$range[1], Country$range[3], Country$range[2], Country$range[4])%>%
     addPolygons(fillOpacity = 0.6,  smoothFactor = 0.5, stroke = TRUE, weight = 1)
})
}


shinyApp(ui =ui, server = server)
库(闪亮)
图书馆(单张)
图书馆(地图)
ui%
addPolygons(fillOpacity=0.6,smoothFactor=0.5,stroke=TRUE,weight=1)
})
}
shinyApp(用户界面=用户界面,服务器=服务器)

有很多国家的纬度和经度列表,例如:。这就是你要找的吗?我真的以为会有一个包存储这些值。这也很有帮助。非常感谢。