首页 文章

使用纬度和经度找出POI(2公里以内)

提问于
浏览
1

我有一个数据集,其中包含Zipcode以及lat和log . 我想从该纬度和经度中找出医院/银行列表(2公里内) .

怎么做?

Long / Lat数据看起来像

store_zip   lon lat
410710    73.8248981    18.5154681
410209    73.0907       19.0218215
400034    72.8148177    18.9724162
400001    72.836334     18.9385352
400102    72.834424     19.1418961
400066    72.8635299    19.2313448
400078    72.9327444    19.1570343
400078    72.9327444    19.1570343
400007    72.8133825    18.9618411
400050    72.8299518    19.0551695
400062    72.8426858    19.1593396
400083    72.9374227    19.1166191
400603    72.9781047    19.1834148
401107    72.8929       19.2762702
401105    72.8663173    19.3053477
400703    72.9992013    19.0793547
401209          NA          NA
401203    72.7983705    19.4166761
400612    73.0287209    19.1799265
400612    73.0287209    19.1799265
400612    73.0287209    19.1799265

1 回答

  • 5

    如果您的兴趣点未知并且您需要找到它们,则可以通过我的 googleway 包使用Google的API(正如您在评论中所建议的那样) . 您需要一个有效的API密钥才能实现此目的 .

    由于API一次只能接受一个请求,因此您需要一次迭代一行数据 . 为此,您可以使用您最喜欢的循环方法

    library(googleway) ## using v2.4.0 on CRAN
    
    set_key("your_api_key")
    
    lst <- lapply(1:nrow(df), function(x){
    
      google_places(search_string = "Hospital", 
                    location = c(df[x, 'lat'], df[x, 'lon']),
                    radius = 2000)
    
    })
    

    lst 现在是一个包含查询结果的列表 . 例如,它为第一行数据返回的医院名称是

    place_name(lst[[1]])
    
    # [1] "Jadhav Hospital"                                                
    # [2] "Poona Hospital Medical Store"                                   
    # [3] "Sanjeevan Hospital"                                             
    # [4] "Suyash Hospital"                                                
    # [5] "Mehta Hospital"                                                 
    # [6] "Deenanath Mangeshkar Hospital"                                  
    # [7] "Sushrut Hospital"                                               
    # [8] "Deenanath Mangeshkar Hospital and Research Centre"              
    # [9] "MMF Ratna Memorial Hospital"                                    
    # [10] "Maharashtra Medical Foundation's Joshi Multispeciality Hospital"
    # [11] "Sahyadri Hospitals"                                             
    # [12] "Deendayal Memorial Hospital"                                    
    # [13] "Jehangir Specialty Hospital"                                    
    # [14] "Global Hospital And Research Institute"                         
    # [15] "Prayag Hospital"                                                
    # [16] "Apex Superspeciality Hospital"                                  
    # [17] "Deoyani Multi Speciality Hospital"                              
    # [18] "Shashwat Hospital"                                              
    # [19] "Deccan Multispeciality Hardikar Hospital"                       
    # [20] "City Hospital"
    

    您还可以在 Map 上查看它们

    set_key("map_api_key", api = "map")
    
    
    ## the lat/lon of the returned results are found through `place_location()`
    # place_location(lst[[1]])
    
    df_hospitals <- place_location(lst[[1]])
    df_hospitals$name <- place_name(lst[[1]])
    
    google_map() %>%
      add_circles(data = df[1, ], radius = 2000) %>%
      add_markers(data = df_hospitals, info_window = "name")
    

    enter image description here

    注意:

    • Google的API每天每个密钥限制为2,500次查询,除非您支付高级帐户 .

相关问题