从Google地方信息自动填充和路线脚本中获取纬度和经度
有谁知道如何从谷歌广告自动完成和方向脚本中获取纬度和经度?
https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-directions
我想将纬度和经度值传递给隐藏字段,如下所示:
-
从
AutocompleteOptions
删除{placeIdOnly: true}
。 使用该集合,place
对象仅包含该place
的name
和placeId
。 -
从这个
place
对象获取经度和经度,如下所示:
document.getElementById("latitude").value= place.geometry.location.lat(); document.getElementById("longitude").value= place.geometry.location.lng();
概念certificate小提琴
代码段:
// This example requires the Places library. Include the libraries=places // parameter when you first load the API. For example: //
/* Always set the map height explicitly to define the size of the div * element that contains the map. */ #map { height: 100%; } /* Optional: Makes the sample page fill the window. */ html, body { height: 100%; margin: 0; padding: 0; } .controls { margin-top: 10px; border: 1px solid transparent; border-radius: 2px 0 0 2px; box-sizing: border-box; -moz-box-sizing: border-box; height: 32px; outline: none; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3); } #origin-input, #destination-input { background-color: #fff; font-family: Roboto; font-size: 15px; font-weight: 300; margin-left: 12px; padding: 0 11px 0 13px; text-overflow: ellipsis; width: 200px; } #origin-input:focus, #destination-input:focus { border-color: #4d90fe; } #mode-selector { color: #fff; background-color: #4d90fe; margin-left: 12px; padding: 5px 11px 0px 11px; } #mode-selector label { font-family: Roboto; font-size: 13px; font-weight: 300; }