无法使用传单R在地图上添加标记

时间:2015-12-11 16:42:57

标签: r postgresql leaflet openstreetmap

我在这个R代码中有一个简单的问题:

main_visualization <- function(){
  library(leaflet)
  library(RPostgreSQL)

  # Get a database connection
  con <- connectDB()

  # Reading the required table from the database to company dataframe
  c_df <- dbReadTable(con, "custom_ways_filtered")  
  dbDisconnect(con)

  c_df <- c_df[c("tags","latitude","longitude")]

  c_longitude <- as.numeric(c_df$longitude)
  c_latitude <- as.numeric(c_df$latitude)

  leaflet(data = c_df) %>% addTiles() %>% setView(-93.65, 42.0285, zoom = 4) %>%
    addMarkers(~c_longitude, ~c_latitude, popup = ~as.character(c_df$tags))

}#END of main_visualization()

我正在从postgresql数据库中读取一个表。该表包含有关建筑物的OSM信息,我已经检查过我需要从数据库中检索R代码中的所有内容。然后我使用Leaflet API在地图上显示标记。为了做到这一点,我从已经从postgres表中检索数据的数据帧获得lat / lon。但是我没有在地图上找到标记,而是什么都没有。数据框的大小为 1624 个实例。

请帮助我解决问题。我一直关注this Leaflet博客。我也搜索过其他一些博客,但无法弄清楚我哪里出错了。非常感谢您的时间并期待解决方案。

1 个答案:

答案 0 :(得分:0)

尝试:

c_df$c_longitude <- as.numeric(c_df$longitude)
c_df$c_latitude  <- as.numeric(c_df$latitude)

埃纳尔