# Find a point in a polyline which is the closest to a given latlng

Hi guys.

I have polyline points array [langitude(degrees), latitude(degrees), altitude(meters)] and I need to find the closest point in polyline array to a given point(latitude(degrees) longitude(degrees)).

How can I do it using Cesium API ?

Thank you very much.

Hello,

There isn’t a helper function in the Cesium API to do this, you will have to do your own calculation.

Best,

Hannah

Can you provide an algorithm to do it in Cesium please ?

If you need distance over the curved ellipsoid, Cesium.EllipsoidGeodesic has the surfaceDistance property (http://cesiumjs.org/Cesium/Build/Documentation/EllipsoidGeodesic.html).
If you do not (need to) care about the ellipsoid, you can transform (lon, lat, height) to cartesian and calculate the straight distance (http://cesiumjs.org/Cesium/Build/Documentation/Cartesian3.html).

Regards, Willem

Another question:

How can I find a PROJECTION of the given latlng point on the polyline in Cesium 3D view?

Thank you all.

Correct me if I am wrong, but there is no “projection” in the classic sense in 3D mode. Lat/Lon points are displayed on a model of the Ellipsoid. Cesium uses WGS84 by default. This is configurable to a user defined Ellipsoid.

Correct me if I am wrong, but there is no “projection” in the classic sense in 3D mode. Lat/Lon points are displayed on a model of the Ellipsoid. Cesium uses the WGS84 by default. This is configurable to a user defined Ellipsoid. If you pick a point and you are using the default Ellipsoid the crs for that point would be 4326.

Another question:
How can I find a PROJECTION of the given latlng point on the polyline in Cesium 3D view?

Thank you all.

Can you help me to find a point in a polyline which is the closest to a given latlng in the most effiecient way ?

Test for the bouding box of the polygon first, then use the winding number algorithm, cache your vertices if you are testing many points.