【问题标题】:Rounding the place.geometry.location value in Google Maps API在 Google Maps API 中舍入 place.geometry.location 值
【发布时间】:2018-08-07 22:01:46
【问题描述】:

我正在使用 Google Maps API 进行反向地理编码(地址查找)。我的代码结果非常详细 Lat Long 为:

(-7.799250499999999, 110.40451239999993)

如何将place.geometry.location结果四舍五入成某位小数?

例如(-7.7992505, 110.4045124)

这是我的代码方案:

在我的 HTML 中

<div id="infowindow-content">
    <span id="place-coord"></span>
</div>

在我的 Javascript 中

...    
function() {
    ...
    infowindowContent.children['place-coord'].textContent = place.geometry.location;
    ...
}
...

我曾尝试使用:

place.geometry.location.toUrlValue(precision?:number)

place.geometry.location.toUrlValue(precision?:7)

并导致一些崩溃。

任何帮助将不胜感激。谢谢

【问题讨论】:

  • 你试过toFixed方法吗?
  • I had tried to use: ... 可能只需要place.geometry.location.toUrlValue(7)
  • 它有效。谢谢你杰罗姆

标签: javascript php google-maps-api-3 location coordinates


【解决方案1】:

precision?:number 代码必须替换为整数。

place.geometry.location.toUrlValue(WriteYourDesiredPrecisionHere)

在这个问题中,应该是:

place.geometry.location.toUrlValue(7)

【讨论】:

    猜你喜欢
    • 2012-04-23
    • 1970-01-01
    • 2014-06-08
    • 1970-01-01
    • 1970-01-01
    • 2012-10-12
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    相关资源
    最近更新 更多