Maps api: check if a marker falls to the left or r

2019-09-19 15:33发布

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条回答
别忘想泡老子
2楼-- · 2019-09-19 16:06

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
查看更多
登录 后发表回答