Skip to main content
4 of 4
deleted 531 characters in body
Rod
  • 3.3k
  • 2
  • 25
  • 41

This is only an attempt to answer the question, if I understood it correctly. You want to "cover the actual road connection between cities (...) based on the GoogleMap".

First step: find the coordinates of the two cities you want to use as edges in your graphic:

c1 = CityData["Sao Paulo", "Coordinates"];
c2 = CityData["Rio de Janeiro", "Coordinates"];

Second step: define the center of the map:

center = (c1 + c2)/2;

Third step: Import[] the actual Google Maps image based on the center you've specified

Import["http://maps.google.com/maps/api/staticmap?center=" <>ToString[center[[1]]] <> "," <> ToString[center[[2]]] <> "&zoom=6&size=400x400&sensor=false&maptype=roadmap&markers=color:blue%7Clabel:O%7C" <> ToString[c1[[1]]] <> "," <> ToString[c1[[2]]] <>"&markers=color:red%7Clabel:D%7C" <> ToString[c2[[1]]] <> "," <> ToString[c2[[2]]]]

enter image description here

EDITED

After some research, I think it can also be done:

Define the cities:

from = ToString[c1[[1]]] <> "," <> ToString[c1[[2]]];
to = ToString[c2[[1]]] <> "," <> ToString[c2[[2]]];

Now use Mathematica to import data from Google with distance and time:

distdata = Import["http://maps.googleapis.com/maps/api/directions/json?origin=" <> from <> "&destination=" <> to <> "&region=es&sensor=false", {"HTML", "Source"}];

Now find distance by road:

roadDistance = StringSplit[StringSplit[distdata, ":"][[13]],","][[1]]

"429 km"

Now find travel time:

travelTime = StringSplit[StringSplit[distdata, ":"][[16]], ","][[1]]

"4 hours 44 mins"

Rod
  • 3.3k
  • 2
  • 25
  • 41