Maps api: check if a marker falls to the left or right of a polyline

扶醉桌前 提交于 2020-01-07 06:40:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!