Google maps api v3 polylines snap to nearest stree

2019-07-29 02:59发布

Assuming i have a list of positions from a GPS unit loaded into a database. Now i would like Google maps to show these positions, which works just out of the box like this

new google.maps.LatLng(57.046085209585726, 9.917740747332573),
                        new google.maps.LatLng(57.04606626648456, 9.918211475014687),
                        new google.maps.LatLng(57.04656251706183, 9.917992874979973),
                        new google.maps.LatLng(57.04649009741843, 9.918401995673776),
                        new google.maps.LatLng(57.04628427978605, 9.91844767704606),
                        new google.maps.LatLng(57.04613022040576, 9.91837676614523),
                        new google.maps.LatLng(57.045781994238496, 9.918353715911508),
                        new google.maps.LatLng(57.045685979537666, 9.918150706216693),
                        new google.maps.LatLng(57.0457204291597, 9.917718200013041),
                            new google.maps.LatLng()

The problem is. That the polylines cut corners and due to less correct GPS devices it will look like you walked through a building and swimmingpool to get to the other side of the street. Is there any way i can make my positioning data from the database snap to the nearest street?

Thank you all Jonas

1条回答
霸刀☆藐视天下
2楼-- · 2019-07-29 03:52

Not that I am aware of. You could try using the Directions API to request directions between the points but there is a limit of eight waypoints per request, you can break longer lists of points into sublists and make multiple directions calls but there are limits on the number of calls allowed to the service.
Another problem with this approach is if due to minor inaccuracies in your data or the map data you, for example, appear to be on the wrong side of the road it might generate spurious U turns and trips around roundabouts.

The standard Google map web user interface has a line drawing tool with a 'snap to road' option but this option was not included in the API version of the drawing manager. I did submit an enhancement request http://code.google.com/p/gmaps-api-issues/issues/detail?id=3824&can=4&sort=-stars&colspec=ID%20Type%20Status%20Introduced%20Fixed%20Summary%20Stars%20ApiType%20Internal but no response yet. You could star the issue and/or create your own request since you issue isn't quite the same.

查看更多
登录 后发表回答