Search code examples
lineopenlayers-3

How to predict the future trajectory position and draw a line based on the current speed and course of the aircraft in openlayers 3?


I wanted to draw a vector line of the plane's current speed and heading to predict its future position, with a solid point added every five minutes. I didn't know how to do that. look like this


Solution

  • The formula using spherical geometry is given here https://www.movable-type.co.uk/scripts/latlong.html (ellipsoidal geometry would be slightly more accurate but more complex)

    var lat2 = Math.asin( Math.sin(lat1)*Math.cos(distance/radius) +
                        Math.cos(lat1)*Math.sin(distance/radius)*Math.cos(bearing) );
    var lon2 = lon1 + Math.atan2(Math.sin(bearing)*Math.sin(distance/radius)*Math.cos(lat1),
                             Math.cos(distance/radius)-Math.sin(lat1)*Math.sin(lat2));
    

    OpenLayers uses 6371008.8 meters for the Earth's radius

    distance would be calculated from time*speed in the same units