【问题标题】:Get Timezone from Google Places api autocomplete从 Google Places api 自动完成获取时区
【发布时间】:2021-01-17 10:40:41
【问题描述】:

我正在尝试从 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&amp;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 information you are looking for.
 
  document.getElementById("latitude").value = place.geometry['location'].lat();
  document.getElementById("longitude").value = place.geometry['location'].lng();
  });
}
</script>

【问题讨论】:

  • 谁能帮帮我?
  • 看起来可能已更改为 utc_offset_minutesutc_offset_minutes
  • 请让我检查一下
  • 我尝试更改此“document.getElementById("utc_offset_minutes").value”,但它不起作用
  • 是的,我明白了。但同样的结果。 :(

标签: javascript google-maps google-places-api


【解决方案1】:

要从 google 地方自动完成中检索时区,请将以下行添加到代码中

  document.getElementById("timezone").value = place.utc_offset_minutes;

也可以使用place.utc_offset

【讨论】:

  • 我已经尝试过了,但不是想要的结果。意味着如果我从谷歌地点地址文本框中选择印度,那么它应该返回的时区应该是 5.5。它的 UTC 偏移量。
  • Google 标准以分钟为单位。为什么不直接划分我的 60?当我搜索印度时,它返回 330。除以 60 得到 5.5。您还可以调查 Google TimeZone Api。
  • 如果这家伙不喜欢分钟,他肯定不会喜欢 Timezone API,因为它是以秒为单位的。
猜你喜欢
  • 2013-10-10
  • 1970-01-01
  • 1970-01-01
  • 2014-05-01
  • 2017-02-04
  • 2017-10-02
  • 1970-01-01
  • 2022-06-19
  • 1970-01-01
相关资源
最近更新 更多