【问题标题】:Get Latitude and Longitude from result of google map v3 direction api?从谷歌地图v3方向api的结果中获取纬度和经度?
【发布时间】:2011-10-15 08:29:10
【问题描述】:

我在我的项目中使用Google map v3 direction api

我将城市名称命名为 start pointend point 以获取该距离的距离和所用时间。

我还有一个要求是获取起点的经度和纬度,即城市名称。

我可以从我用来获取方向 api 结果的距离和时间的方向 api 中获取它吗?

如果我们可以从direction api的结果中得到纬度和经度,那么请通过给出正确的答案帮助我。

提前致谢。

【问题讨论】:

    标签: c# javascript asp.net google-maps-api-3


    【解决方案1】:

    响应不包含 lat/lng 字符串。您必须使用函数来获取它。

    使用 jquery 这对我有用。

    $.each(result.routes[0].legs, function(index, route) {
    alert(route.start_location.lat());
    });
    

    这将提醒您请求的每段旅程的每个起始纬度。

    【讨论】:

      【解决方案2】:

      快速查看responses section of the directions API documentation ,您似乎可以获得 start_location -> lat 和 start_location -> lng,就像您已经获得距离和时间一样。

      我猜应该是:

      routes.legs[0].start_location.lat
      routes.legs[0].start_location.lng
      

      【讨论】:

      • 代码的输出是:- function () { return this[a]; }
      • 您如何将用于获取距离和时间的代码放入您的问题中?这样就更容易正确回答了。
      • 警报(route.legs[0].start_location.lat.value);
      • 以上是你的代码,这是我双向尝试的!!!!!!!有价值没有价值..有价值它给了我“未定义”......没有我说你早。
      • 绝对应该没有value。我得到了 routes (以 s 结尾),你得到了 route 。 myba 有什么问题吗?试试route.legs[0].start_location.lat
      猜你喜欢
      • 2013-03-03
      • 1970-01-01
      • 1970-01-01
      • 2016-01-29
      • 1970-01-01
      • 2016-04-03
      • 1970-01-01
      • 1970-01-01
      • 2012-09-28
      相关资源
      最近更新 更多