GoogleMaps Polyline Length in V3

后端 未结 7 1203
半阙折子戏
半阙折子戏 2020-12-10 23:30

There doesn\'t seem to be a length funciton for the Polyline in Google Maps anymore in V3.

Has anyone found a workaround for this functionality gap?

7条回答
  •  臣服心动
    2020-12-10 23:47

    I went looking for the same information and found that the api call you're looking for is in the geometry.spherical namespace.

    Here's the code I'm using:

    //Path is the mvc array of lat/lng that makes up the polyline
    var path = $scope.courseLine.getPath();
    
    $scope.totalDistance = google.maps.geometry.spherical.computeLength(path);
    $scope.totalMiles = ($scope.totalDistance * 0.00062137).toFixed(2) + " mi";
                    });
    

提交回复
热议问题