# Ionic native google maps : how to connect 2 marker on map and count the distance

**URL:** <https://forum.ionicframework.com/t/ionic-native-google-maps-how-to-connect-2-marker-on-map-and-count-the-distance/142273>\
**Category:** ionic-v3\
**Created:** [September 19, 2018, 11:14pm UTC](https://forum.ionicframework.com/t/ionic-native-google-maps-how-to-connect-2-marker-on-map-and-count-the-distance/142273 "2018-09-19T23:14:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![elwanta](https://avatars.discourse-cdn.com/v4/letter/e/c77e96/32.png) [@elwanta](https://forum.ionicframework.com/u/elwanta)\
**Post date:** [September 19, 2018, 11:14pm UTC](https://forum.ionicframework.com/t/ionic-native-google-maps-how-to-connect-2-marker-on-map-and-count-the-distance/142273/1 "2018-09-19T23:14:08Z")

</div>

how to connect 2 marker on map and count the distance between 2 marker?

thanks

---

<div class="post-metadata">

**Author:** ![wf9a5m75](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/wf9a5m75/32/118692_2.png) [@wf9a5m75](https://forum.ionicframework.com/u/wf9a5m75)\
**Post date:** [September 20, 2018, 3:43am UTC](https://forum.ionicframework.com/t/ionic-native-google-maps-how-to-connect-2-marker-on-map-and-count-the-distance/142273/2 "2018-09-20T03:43:36Z")

</div>

> <https://github.com/ionic-team/ionic-native-google-maps/blob/master/documents/spherical/README.md#computedistancebetweenlocationa-locationb>

> <https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v2.3.0/class/utilities/geometry/spherical/computeDistanceBetween/README.md>

---

<div class="post-metadata">

**Author:** ![elwanta](https://avatars.discourse-cdn.com/v4/letter/e/c77e96/32.png) [@elwanta](https://forum.ionicframework.com/u/elwanta)\
**Post date:** [September 20, 2018, 5:15pm UTC](https://forum.ionicframework.com/t/ionic-native-google-maps-how-to-connect-2-marker-on-map-and-count-the-distance/142273/3 "2018-09-20T17:15:51Z")

</div>

picture 1

 ![Screenshot_20180920-230202](https://global.discourse-cdn.com/ionicframework/original/3X/a/7/a7415757dcfe316e6b68bb2c44231733aff65148.jpeg)

picture 2

 ![Screenshot_20180920-230228](https://global.discourse-cdn.com/ionicframework/original/3X/5/9/59896cc4ad804cdc39bb6d36e40227b17343be20.jpeg)

On my application (picture 1), i use computeDistanceBetween() to count the distance between location A and location B, and i use addPolyline to draw the line between 2 locations.

Can i get distance between location A and location B like Google Maps Application (picture 2)?  
because when using computeDistanceBetween() the return value not same like distance on Google Maps Applications?

And can i draw line between 2 locations like on Google Maps Application (fastest route)? not only draw a straight line between 2 locations like picture 1.

---

<div class="post-metadata">

**Author:** ![wf9a5m75](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/wf9a5m75/32/118692_2.png) [@wf9a5m75](https://forum.ionicframework.com/u/wf9a5m75)\
**Post date:** [September 20, 2018, 5:52pm UTC](https://forum.ionicframework.com/t/ionic-native-google-maps-how-to-connect-2-marker-on-map-and-count-the-distance/142273/4 "2018-09-20T17:52:02Z")

</div>

`computeDistanceBetween()` calculates the distance (in meters) two linear points.

In order to get the routes of two points, you need to implement [Google Maps Directions API](https://developers.google.com/maps/documentation/directions/start) by yourself.

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:16pm UTC](https://forum.ionicframework.com/t/ionic-native-google-maps-how-to-connect-2-marker-on-map-and-count-the-distance/142273/5 "2021-07-19T21:16:24Z")

</div>


