开发者

Maps Api: DirectionRenderer from latlng 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜