【问题标题】:Google Map Bound Calculation without Javascript没有Javascript的谷歌地图边界计算
【发布时间】:2011-12-10 04:01:59
【问题描述】:

有人知道如何在不使用任何 UI 元素和 Javascript 的情况下完成谷歌地图边界计算。

我有一组点和不同的缩放级别。我可能可以添加屏幕尺寸,我需要计算提供的坐标和缩放级别的界限。我正在尝试在纯 C# 代码中执行此操作。

请帮忙。

【问题讨论】:

  • 更清洁的解决方案是使用 api 在 javascript 中执行此操作,然后可能使用 ajax 与服务器通信,...

标签: google-maps google-maps-api-3


【解决方案1】:

至于计算边界 - 您可以通过遍历坐标数组来轻松完成,如果点掉了则扩展边界矩形。第一个坐标是一个开始。我不熟悉 C#,但有使用伪代码的算法:

points = Array of coord(lat, lng)
bounds = object {
  top: null
  left: null
  right: null
  bottom: null

  function extend(coord: (lat, lng))
  {
    if (this.top == null) // empty
    {
      this.top = coord.lat; this.bottom = coord.lat;
      this.left = coord.lng; this.right = coord.lng;
    }
    else
    {
       if (coord.lng < this.left) this.left = coord.lng;
       if (coord.lat < this.bottom) this.bottom = coord.lat;
       if (coord.lng > this.right) this.right = coord.lng;
       if (coord.lat > this.top) this.top = coord.lat;
    }
  }
}

当然,更简单的方法是使用已经编写好的谷歌功能。 缩放级别可以通过边界框的大小以某种方式计算(例如,您可以找到一个以公里或英里/像素为单位的表格,或近似宽度或地图),但最舒适的方式是 map.fitBounds(bounds)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-10
    相关资源
    最近更新 更多