# Android QuestionDistance between two map points and time needed to travel

#### Inman

##### Well-Known Member
Longtime User
I need to find the distance between two geo coordinates on Google Maps. I see that the GPS library has a DistanceTo option. My question is, does the function use a driving route (via road) based on the city's Google Map or is it calculating the distance between the coordinates as a straight line, using some mathematical formula?

If possible, I would also like to get an estimated driving time between the two geo coordinates.

#### derez

##### Expert
Longtime User
is it calculating the distance between the coordinates as a straight line, using some mathematical formula?
Yes (and no, it is actually the distance on a Great Circle of Earth)

#### Inman

##### Well-Known Member
Longtime User
That is sad. Looks like I will have to use the web API now.

Btw is it possible to plot on Google Maps, a driving road route between two points?

#### derez

##### Expert
Longtime User
But it plots the route by itself in Google Maps! (from your present position to the destination point).

#### Inman

##### Well-Known Member
Longtime User
Yes that is what I need. I want to mark two points on Google Maps and it should display the driving route connecting them.

Can I do that?

##### Active Member
Longtime User
inman, did you solve this problem ?, I would like to know that too

#### derez

##### Expert
Longtime User
Like I wrote above, Google maps calculates and shows the route from your position to a marked point:
Turn Google maps on and let the GPS work. You see your position on the map.
Touch a point on the map and you'll have it marked (a baloon icon).
On the bottom left there is an icon of car - press it - you get driving instruction and the route.

#### Inman

##### Well-Known Member
Longtime User
inman, did you solve this problem ?, I would like to know that too

Here is how I did:
1. Using Google Directions API, I got the polylines point string
2. Using MapsDecodePolyline function given here, I converted point string into a list of points
3. I drew the line connecting the points using GoogleMaps.AddPolyLine, using the list of points from step 2

##### Active Member
Longtime User
Here is how I did:
1. Using Google Directions API, I got the polylines point string
2. Using MapsDecodePolyline function given here, I converted point string into a list of points
3. I drew the line connecting the points using GoogleMaps.AddPolyLine, using the list of points from step 2
Looks complicated, Do you mind to share the code of your project ?, I mean, only the code related to this topic.

#### imbault

##### Well-Known Member
Longtime User

B4X:
``````**************************************
LOCAL cUrl, oHTTP, oXMLDOM, oOrigine
LOCAL oDestination,oState,ocDuree,ovDuree ,ocDistance, ovDistance

oHTTP = CreateObject("MSXML2.XMLHTTP")
oHTTP.Open("GET", cURL, .f.)
oHTTP.Send
oXMLDOM = oHTTP.responseXML

IF oOrigine.length != 1 then
RETURN ("")
ELSE

ciao = oOrigine.item(0).text
ENDIF
IF NOT USED("distance")
CREATE CURSOR distance (nom c(50),  jour date, depart c(70), arrivee c(70), duree c(15), durees N(10), distance c(15), distancem n(10),  etat L)
endif
oState = oXMLDOM.selectNodes("//status")
ocDuree = oXMLDOM.selectNodes("//duration / text")
ovDuree = oXMLDOM.selectNodes("//duration / value")
ocDistance = oXMLDOM.selectNodes("//distance / text")
ovDistance = oXMLDOM.selectNodes("//distance / value")

FOR i= 0 TO odestination.length -1

IF ostate.item(i).text = 'OK' THEN

INSERT INTO distance(nom, jour,depart, arrivee, duree, durees, distance, distancem, etat) VALUES ;
(cNom, CTOD(cJour),ciao,oDestination.item(i).text ,ocDuree.item(i).text, VAL(ovDuree.item(i).text), ocDistance.item(i).text, VAL(ovDistance.item(i).text),.T.)
ELSE
**INSERT INTO distance(depart, arrivee, duree, distance,etat) VALUES ;
(ciao,'NON GEOCODEE' ,',',.F.)
ENDIF
NEXT``````

#### Beja

##### Expert
Longtime User
Hi Martin,
Is it stable? I want to try it

Replies
6
Views
2K
Replies
3
Views
1K
Replies
25
Views
3K
Replies
9
Views
4K
Android Question Distance between two points
Replies
6
Views
2K