How to draw a polygon in google map using many coordinates

前端 未结 2 965
执笔经年
执笔经年 2021-01-07 03:04

I have an array containing latitude and longitude of different location which is displayed in the google map. Now I need to make a polygon passing through all these points.

2条回答
  •  南笙
    南笙 (楼主)
    2021-01-07 03:41

    Just take the example you took and add more points.

    However, with more than three points, you'll have intersection trouble if you don't sort the coordinates properly.

    To fix it you'll need an algorithm:

    Here is the answer: Sorting points to avoid intersections.

    You can stop at the second point of the answer, you just calculate the center of your polygon and then the angles to sort the points.

    However, you can't use latitude and longitude with this algorithm.

    For this scale you can just project your coordinates to a 2d plane.

    Go for this: merkator projection

提交回复
热议问题