开发者

Maps Api: DirectionRenderer from latlng array

开发者 https://www.devze.com 2023-03-12 01:29 出处:网络
I have an array of latlng objects. I want to show a DirectionsRenderer along the points in this array.

I have an array of latlng objects.

I want to show a DirectionsRenderer along the points in this array. When you create a DirectionsRenderer, it seems you c开发者_C百科an only give a DirectionsResult as the direction.


Send the DirectionsService a DirectionsRequest that contains your start point, your end point, and then all your other LatLng objects as waypoints. (You'll need to put them in a DirectionsWaypoint object.) That should return a route a DirectionsResult from the DirectionsService that matches your array of LatLng objects if your LatLng objects correspond to a real route along a road or whatever.

If you are hoping to draw arbitrary lines using the DirectionsRenderer rather than a route that Google Maps might come up with, then you probably should probably look at other ways to do it. You are correct that the DirectionsRenderer needs to receive a DirectionsResult object. Anything you do to thwart that requirement is likely to just cause headaches sooner or later.

0

精彩评论

暂无评论...
验证码 换一张
取 消