how to send request to google maps for distances matrix

hello i have registered for API key but donot know how to send request for distance matrix in google maps

locations = c("lahore", "rawalpindi", "karachi")
doc = mp_matrix(
origins = locations,
destinations = locations
)
doc = as_xml_document(response_matrix)

m = mp_get_matrix(doc, value = "distance_m")
colnames(m) = locations
rownames(m) = locations
m

it is giving every time same distance for different locations

Why don't you calculate the distances yourself? I used geosphere::distHaversine

data %>%
  mutate(dist = geosphere::distHaversine(c(mylong, mylat), c(long, lat))/1000)

actually i have to open google maps in R and select random points on google maps

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.