Android Question Calculate many marker on polyline

yfleury

Active Member
Licensed User
Longtime User
I have a polyline between 2 coordinate.
Location1(lat1, lon1)
Location2(lat2, lon2)
I know how to set a marker in center of polyline with
Marker1( (lat1+lat2)/2 , (lon1+lon2)/2 ) that is working fine

But when polyline is very long (100 meters) I want to put on polyline a marker every 20 meters.
How to calculate coordinate for each marker to add to polyline?
 
Solution
Thank @emexes But You have an error. This will work perfectly. Missplace of )
B4X:
For I = 0 to NumMarkers
    Marker1((lat1 + (lat2 - lat1) * I / NumMarkers), (lon1 + (lon2 - lon1) * I / NumMarkers))
Next

emexes

Expert
Licensed User
But when polyline is very long (100 meters) I want to put on polyline a marker every 20 meters.
How to calculate coordinate for each marker to add to polyline?

B4X:
Dim LineLength as float = 100    '100 meters long
Dim MarkerSpacing As Float = 20    'every 20 meters (or thereabouts, so that is evenly spaced, and end markers are at ends of line)

Dim NumMarkers As Int = LineLength / MarkerSpacing + 2

For I = 0 to NumMarkers
    Marker1(lat1 + ((lat2 - lat1) * I) / NumMarkers, lon1 + ((lon2 - lon1) * I) / NumMarkers)
Next
 
Last edited:
Upvote 0

emexes

Expert
Licensed User
I know how to set a marker in center of polyline with
Marker1( (lat1+lat2)/2 , (lon1+lon2)/2 ) that is working fine

Super-minor point, more of interest than of real-life effect, but:

finding the midpoint by averaging coordinates is only precisely correct when either the line is on a meridian (north-south line), or on the equator, or equally north and south of the equator. But it's close enough. šŸ» I often do worse when I assume a patch of earth is retangular rather than spherical.

Another super-minor point is that airplanes weigh less when flying east than when flying west, thanks to increased centrifugal effect.
 
Last edited:
Upvote 0

yfleury

Active Member
Licensed User
Longtime User
Thank @emexes But You have an error. This will work perfectly. Missplace of )
B4X:
For I = 0 to NumMarkers
    Marker1((lat1 + (lat2 - lat1) * I / NumMarkers), (lon1 + (lon2 - lon1) * I / NumMarkers))
Next
 
Upvote 0
Solution

yfleury

Active Member
Licensed User
Longtime User
Super-minor point, more of interest than of real-life effect, but:

finding the midpoint by averaging coordinates is only precisely correct when either the line is on a meridian (north-south line), or on the equator, or equally north and south of the equator. But it's close enough. šŸ» I often do worse when I assume a patch of earth is retangular rather than spherical.

Another super-minor point is that airplanes weigh less when flying east than when flying west, thanks to increased centrifugal effect.
For now, I work under 10 km
 
Upvote 0

yfleury

Active Member
Licensed User
Longtime User
Marqueur1((lat1 + (lat2 - lat1) * I) / NumMarkers, (lon1 + (lon2 - lon1) * I) / NumMarkers)
 
Upvote 0
Top