問題描述
如何在谷歌地圖API中獲取高速公路和道路的緯度和經度 (How to get Latitude and Longitude of highways and roads in Google maps API)
在我的公司,我們使用 Google 地圖 API 對地址進行地理編碼以獲取緯度和經度。Fpor城市,它工作正常。但是當我們必須找到高速公路/道路的緯度/經度時,它沒有數字。我們只有地址的名稱/代碼及其公里/英里位置(即:50 公里處的 BR‑060,或:150 英里處的班德蘭特斯高速公路)。
我住在巴西,所以也許我們使用的表達式不匹配,但我想知道是否有辦法找到這些地址的緯度/經度,因為我們找不到它們。我們試圖查看 Google 的文檔,但沒有成功。
參考解法
方法 1:
Here's an example that shows how the Google Autoocomplete API returns back the latitude and longitude
var autocomplete = new google.maps.places.Autocomplete(street);
google.maps.event.addListener(autocomplete, 'place_changed', function() {
var place = autocomplete.getPlace().geometry.location;
document.getElementById("lat").value = place.lat();
document.getElementById("lon").value = place.lng();
});
input {
width: 400px;
}
<script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=places&dummy=.js"></script>
<form>
<input type="text" id="street" name="street" placeholder="street">
<br>
<input type="text" id="lat" placeholder="lat">
<br>
<input type="text" id="lon" placeholder="lon">
<br>
</form>
(by Eduardo Samoggin、camiblanch)