Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google maps 在Google Maps Apiv3中获取由方向服务生成的路线上的所有坐标_Google Maps_Google Maps Api 3_Map Directions - Fatal编程技术网

Google maps 在Google Maps Apiv3中获取由方向服务生成的路线上的所有坐标

Google maps 在Google Maps Apiv3中获取由方向服务生成的路线上的所有坐标,google-maps,google-maps-api-3,map-directions,Google Maps,Google Maps Api 3,Map Directions,我的应用程序允许用户选择地图上的两个点,并使用谷歌地图Apiv3的方向服务找到它们之间的路线。然后必须将沿此路线的坐标保存到数据库中。我可以成功地编写所有代码来实现这一点。然而,我被一个问题遗漏了 我知道在同一个问题上还有其他几个问题,但我想肯定不是他们就是我漏掉了一些东西 示例代码: function getCoordinates(result) { var currentRouteArray = result.routes[0]; //Returns a compl

我的应用程序允许用户选择地图上的两个点,并使用谷歌地图Apiv3的方向服务找到它们之间的路线。然后必须将沿此路线的坐标保存到数据库中。我可以成功地编写所有代码来实现这一点。然而,我被一个问题遗漏了

我知道在同一个问题上还有其他几个问题,但我想肯定不是他们就是我漏掉了一些东西

示例代码:

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);
            }
      }
函数getCoordinates(结果){ var currentRouteArray=result.routes[0];//返回包含当前路由结果的复杂对象 var currentRoute=currentRouteArray.overview_path;//返回路径上所有坐标的简化版本 obj_newPolyline=new google.maps.Polyline({map:map});//仅用于验证我的代码正在获取坐标的多段线 var path=obj_newPolyline.getPath(); 对于(var x=0;x 上述代码工作正常,但似乎保持lat和lng坐标的概览路径的
kb
lb
属性并不总是相同。上次我做代码时,它是
kb
lb
,持续了几天,后来它变为
mb
nb
,今天是
jb
kb


我在对象中没有看到任何其他属性可以为我提供除上述属性以外的其他属性。其他类似问题的答案都没有提到这个问题。我是不是遗漏了什么?请提供任何可靠的解决方案。

不要使用kb和lb,它们是缩小的名称,并且没有文档记录。仅使用记录的属性.lat()和.lng()

另一个选项是解码“点”字符串:

它比对每个点使用lat()/lng()方法快得多

http://home.provide.net/~bratliff/routes/