问题描述
我正在尝试从Google地方信息中获取纬度,经度和时区(印度5.30)。地址由自动填充功能填充,从而获得纬度和经度。但是我无法获得时区。我正确地获得了纬度和经度。谁能帮助我获取时区。我的代码如下:
HTML
<input id="address" type="text" placeholder="Enter address here" />
<div>
<p>Latitude:
<input type="text" id="latitude" readonly />
</p>
<p>Longitude:
<input type="text" id="longitude" readonly />
</p>
<p>Timezone:
<input type="text" id="timezone" readonly />
</p>
</div>
脚本
<script src="https://maps.googleapis.com/maps/api/js?key=API_KEY&libraries=places"></script>
<script>
google.maps.event.addDomListener(window,'load',initialize);
function initialize() {
var input = document.getElementById('address');
var autocomplete = new google.maps.places.Autocomplete(input);
autocomplete.addListener('place_changed',function () {
var place = autocomplete.getPlace();
// place variable will have all the @R_710_4045@ion you are looking for.
document.getElementById("latitude").value = place.geometry['location'].lat();
document.getElementById("longitude").value = place.geometry['location'].lng();
});
}
</script>
解决方法
要从Google Places自动检索时区,请在代码中添加以下行
document.getElementById("timezone").value = place.utc_offset_minutes;
一个人也可以使用place.utc_offset