我的应用程序允许用户在地图上选择两个点,并使用Google Maps APIv3的Directions Service找到它们之间的路线。然后,沿着这条路线的坐标必须保存到数据库中。我已经成功编写了所有代码来完成这个任务。但是,我遇到了一个问题。
我知道StackOverflow上有几个类似的问题- 一个,两个,但我认为肯定他们或者我在这里漏掉了某些东西。
示例代码:
function getCoordinates(result) {
var currentRouteArray = result.routes[0]; //Returns a complex object containing the results of the current route
var currentRoute = currentRouteArray.overview_path; //Returns a simplified version of all the coordinates on the path
obj_newPolyline = new google.maps.Polyline({ map: map }); //a polyline just to verify my code is fetching the coordinates
var path = obj_newPolyline.getPath();
for (var x = 0; x < currentRoute.length; x++) {
var pos = new google.maps.LatLng(currentRoute[x].kb, currentRoute[x].lb)
latArray[x] = currentRoute[x].kb; //Returns the latitude
lngArray[x] = currentRoute[x].lb; //Returns the longitude
path.push(pos);
}
}
除了概览路径中似乎保存了纬度和经度坐标的kb
和lb
属性不总是相同之外,上述代码完美运行。上次我编写代码时,它持续了几天,后来变成了mb
、nb
,今天又是jb
和kb
。
我没有看到对象中提供其他经纬度信息的属性。回答其他类似问题的答案没有提到这个问题。我是否漏掉了什么?请提供可靠的解决方案。