Line String Distance

So, I'm creating a GPS, and I would like to know the distance that they traveled. Is there any way I could do this? Thanks!

Welcome Matthew.

You calculate the length of a LineString distance track like this

Sorry, is there a gallery link to this, so I can test it out and see how it works? Thanks!

Sorry no aia, you got to make the blocks from the code, then try it. If you have problems return here and show the blocks you tried. It works provided you have at least two sets of coordinates in the linestring.



Thats the code and user interface, if that helps. I'm not sure what that function does. Sorry if I'm asking too much. But could you maybe help me on like stuff to improve?

The distanceLineString Procedure calculates the sum of all the LineString segments (or legs if you will) in your trak LineString. The procedure can be built using calls to either the distanceBetweenLocationsMiles Procedure or the distanceBetweenLocationsKilometers Procedure (depending on whether you want the distance in miles or kilometers). :wink:

The Map1.DoubleTapAtPoint builds an example linestring. It is there only to demonstrate how the calculation of distance works in the demonstration aia. Your app doesn't need it, your app only needs the Procedures to link with your LineString.

linestringLengthDistance.aia (5.0 KB)

I have difficulty reading the Blocks you show how you build a Track. There are less complicated ways to do it so I am at a loss to provide you suggestions on how to improve your code. Sri. Draw walking route to canvas - #2 by SteveJG

It's fine, thanks for the tips btw. Is there a way just in general to find the distance between two marker points? Thanks!

1 Like

There are several ways

Using Marker tool:

DistanceToFeature(mapFeature,centroids) computes the distance between the Marker and the given mapFeature. If centroids is true, the computation is done between the centroids of the two features. Otherwise, the distance will be computed between the two features based on the closest points. Further, when centroids is false, this method will return 0 if the Marker intersects or contains the mapFeature. If an error occurs, this method will return -1.

The mapFeature can be another Marker :wink:

DistanceToPoint(latitude,longitude)
Compute the distance, in meters, between a Marker and a latitude, longitude point.

Using the coordinates of Marker and Marker2 use the distance Procedure described above . Use calls to either the distanceBetweenLocationsMiles Procedure or the distanceBetweenLocationsKilometers Procedure (depending on whether you want the distance in miles or kilometers)

Good luck with your Project.

Regarding the blocks you already showed using Navigation, you can obtain the distance for the route shown directly from the Navigation.GetDirection Block.

Thank you so much! This is just what I needed!

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