System to measure distance between 2 locations on my website

Asked

Viewed 1,065 times

2

Good morning,

I’m making a site where users need to calculate the distance between two locations. Does anyone know how or where I can use a system that allows me to do this on my website?

  • That in which language?

  • Solved your problem?

1 answer

1

One of the options is to use the API do Google Maps. It returns the distance between two addresses and the average time it takes between the two points.

Ex:

http://maps.googleapis.com/maps/api/distancematrix/json?origins=99010030&destinations=99064090&mode=driving&language=pt-BR&sensor=false

Response:

{
   "destination_addresses" : [ "São Cristovao, Passo Fundo - RS, 99064-090, Brasil" ],
   "origin_addresses" : [ "Vila Popular, Passo Fundo - RS, 99010-030, Brasil" ],
   "rows" : [
      {
         "elements" : [
            {
               "distance" : {
                  "text" : "4,7 km",
                  "value" : 4656
               },
               "duration" : {
                  "text" : "11 minutos",
                  "value" : 652
               },
               "status" : "OK"
            }
         ]
      }
   ],
   "status" : "OK"
}

Follow a nice tutorial I found:

http://cbsa.com.br/post/distancia-entre-cidades---google-maps-javascript-api-v3.aspx

Browser other questions tagged

You are not signed in. Login or sign up in order to post.