How to find the latitude and longitude falls on waypoints using Google API

Deadly 提交于 2019-12-08 13:57:55

问题


I have a group of lat and long which are the stops of a bus.

I need to find the user latitude and longitude is falling on the route.

Find the link to my demo Codepen

I draw the route using waypoints as well as polylines. Using containLocation() function I Can find the user location falls on the route. But it works somewhere in polylines. I need to make this working on waypoints.

If you click near polyline you will get a red circle or blue triangle. Red indicates the point not falling on the route. Blue indicates the point is falling on the route

Any help would be appreciated.


回答1:


I've tried your sample and your code is not following the logic you describe, this is because you are using the wrong containLocation() method this is to see if your location is inside a polygon.

Since you are using a polyine you should use the google.maps.geometry.poly.isLocationOnEdge() method instead. See the Google Maps JavaScript API V3 Reference

As for being able to click on or very close to the waypoint that is impossible because there are no options to make the waypoint object unclickable like with markers at the moment.



来源:https://stackoverflow.com/questions/48821111/how-to-find-the-latitude-and-longitude-falls-on-waypoints-using-google-api

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