2015-12-11 90 views
0

在地图上添加标记我在这个R代码里面一个简单的问题:无法使用单张[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数据库中检索R代码中的所有内容。然后我使用Leaflet API 在地图顶部显示标记。为了做到这一点,我正在从已从postgres表中检索数据的数据框中获取纬度/经度。但是,没有在地图上获得标记,我得到什么也没有。数据帧的大小是实例。

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

回答

0

尝试:

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

埃纳尔