问题
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