【问题标题】:How to find distance only between two places with Google Map API?如何使用 Google Map API 仅查找两个地方之间的距离?
【发布时间】:2016-05-25 05:49:52
【问题描述】:

我是新来使用这个 API。

基本上我正在开发一个计算两地之间运费的小部件,所以我只需要计算距离,不需要显示地图。

如果有人有简单的解释,请与我分享。

我已经查看了this link,但无法确定我只需要使用哪一部分代码来查找距离。

【问题讨论】:

    标签: javascript html google-maps-api-3 widget web-deployment


    【解决方案1】:

    你可以使用GeometrycomputeDistanceBetween()

    var placeA = new google.maps.LatLng(-33.873, 151.13);
    var placeB = new google.maps.LatLng(-33.92, 151.05);
    
    console.log(google.maps.geometry.spherical.computeDistanceBetween(placeA, placeB));
    

    参考:https://developers.google.com/maps/documentation/javascript/geometry#SphericalGeometry

    【讨论】:

    • 非常感谢您的帮助。
    猜你喜欢
    • 2013-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-19
    • 1970-01-01
    • 2016-01-01
    • 2014-10-21
    相关资源
    最近更新 更多