【问题标题】:Google Maps JavaScript API with autocomplete具有自动完成功能的 Google Maps JavaScript API
【发布时间】:2016-10-04 12:17:40
【问题描述】:

我们正在使用 Google API 从自动完成输入中获取地址。

<script src="https://maps.googleapis.com/maps/api/js?key=XXXXX&signed_in=true&libraries=places&callback=initAutocomplete" async defer></script>

源代码可以在这里找到: https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform?hl=de

现在我想知道是否可以从该请求中获取 longitudelatitude。所以我们可以访问谷歌地图并计算到起点的距离。

【问题讨论】:

  • 是的,它在响应中 - 在示例中它是 position.geometry.location - 还有地址的纬度和经度,假设你有相同的“起点” - 你不需要谷歌地图来计算直线距离 - 这只是一些数学
  • @Jaromanda X 谢谢,警报(position.geometry.location);虽然没有价值。我必须使用其他功能吗?
  • 看,你已经发布了零代码,所以我不知道你把那个 alert 调用放在哪里知道你是否做对了
  • 抱歉,再次查看了谷歌地图示例中的代码,您正在寻找的是place.geometry.location - 我很惊讶您没有注意到任何开发人员工具控制台错误,只是说那是“没有价值”-我想知道代码中的那个位置甚至是什么位置,尽管它是未定义的,因此在尝试访问 position.geometry 时会出现异常,更不用说 postion.geometry 了。位置
  • @JaromandaX 谢谢。我通过使用 alert(JSON.stringify(place));在 fillInAddress() 函数中。

标签: javascript api google-maps geolocation


【解决方案1】:

所以解决方案是使用

place.geometry.location.lat() 表示纬度

place.geometry.location.lng() 用于 longtidue

在声明 var 位置后的 fillInAddress() 函数中。

感谢@JaromandaX

【讨论】:

    猜你喜欢
    • 2013-02-10
    • 2012-03-15
    • 2013-12-28
    • 1970-01-01
    • 1970-01-01
    • 2017-05-20
    • 2015-08-26
    • 2013-10-11
    • 2015-03-26
    相关资源
    最近更新 更多