How to integrate Google Distance Matrix API key in R code?

后端 未结 2 906
悲&欢浪女
悲&欢浪女 2021-01-15 04:07

I have registered in Google to obtain more requests of drive time distances. However Google doesn\'t automatically pick up this \"permission\" to run more than 2500 queries

2条回答
  •  独厮守ぢ
    2021-01-15 04:34

    I've written the package googleway to access google maps API where you can specify your token key

    For example
    
    library(googleway)
    key <- "your_api_key"
    
    google_distance(origins = list("houston", "Dallas"),
                    destinations = list("waco, Texas", "San Antonio"),
                    key = key,
                    simplify = FALSE)  ## use simplify = T to simplify to a data.frame
    
    
    [1] "{"                                                                              
    [2] "   \"destination_addresses\" : [ \"Waco, TX, USA\", \"San Antonio, TX, USA\" ],"
    [3] "   \"origin_addresses\" : [ \"Houston, TX, USA\", \"Dallas, TX, USA\" ],"       
    [4] "   \"rows\" : ["                                                                
    [5] "      {"                                                                        
    [6] "         \"elements\" : ["                                                      
    [7] "            {"                                                                  
    [8] "               \"distance\" : {"                                                
    [9] "                  \"text\" : \"299 km\","                                       
    [10] "                  \"value\" : 298585"                                           
    [11] "               },"                                                              
    [12] "               \"duration\" : {"                                                
    [13] "                  \"text\" : \"2 hours 51 mins\","                              
    [14] "                  \"value\" : 10244"                                            
    [15] "               },"                                                              
    [16] "               \"duration_in_traffic\" : {"                                     
    [17] "                  \"text\" : \"2 hours 52 mins\","                              
    [18] "                  \"value\" : 10343"                                            
    [19] "               },"                                                              
    [20] "               \"status\" : \"OK\""                                             
    [21] "            },"
    ... etc
    

提交回复
热议问题