问题
I'm currently developing an app using maps API, I have a polyline that is that start as LatLnt one and ends at LatLng two creating a straight line. If I have a Marker that falls somewhere close to this polyline how would I tell if the marker is to the left or to the right of the polyline?
Are there any API utils that handles such geometric calculations?
回答1:
You have coordinates L0, L1 for starting and ending points of line and marker coordinate P.
Find azimuths for directions L0-L1 and L0-P (heading, bearing)
AL = Azimuth(L0,L1)
AP = Azimuth(L0,P)
and find their difference
DA = AP - AL
if DA < 0 then
DA = DA + 360
if DA < 180 then
left side
else
right side
来源:https://stackoverflow.com/questions/43859103/maps-api-check-if-a-marker-falls-to-the-left-or-right-of-a-polyline