This package is developed to connect to the google map Api, where access to the geocoding of a given adress is retrieved.
This function took an adress as inpute, adress can be speciefed by a name of a place or any other known adress of a place. This function then gets the full content of the given adress, including the latitude and longitude of it from the google map database. The code involved in excution of this function is as follows:
geo_api<-function(address){ quary<-"https://maps.googleapis.com/maps/api/geocode/json" address<- gsub("\\[]","\\+", address) mykey="AIzaSyAkdy_DvV2xo3CkHKpVmgNfCpM7hxmsAEw" totalurl<-paste(quary,"?address=",address,"&key",mykey, sep = "") output<-GET(url=totalurl) http_status(output) data<-content(output) latitude<-data$results[[1]]$geometry$location$lat longitude<-data$results[[1]]$geometry$location$lng location<-data$results[[1]]$formatted_address final<-data.frame(latitude,longitude,location) return(final) }
We compare a well known of longitude and latitude of a given place with the output of the longitude and latitude of the geo?api function, and one invalid adress name (with special characters). here is the code for the unite test:
library(testthat) library(RWebApi) test_that("Checking if the output is same",{ expect_that(geo_api("Paris,France")$latitude,equals(48.856614)) expect_that(geo_api("Paris,France")$longitude,equals(2.3522219)) expect_that(geo_api("Lahore")$latitude,equals(31.5546061)) expect_that(geo_api("Lahore")$longitude,equals(74.3571581)) expect_that(geo_api("Asmara")$latitude,equals(15.3228767)) expect_that(geo_api("Asmara")$longitude,equals(38.9250517)) } )
geo_api("1600+Amphitheatre+Parkway,+Mountain+View,+CA")
geo_api("Paris,France")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.