【问题标题】:Calculating the bounding box using Javascript使用 Javascript 计算边界框
【发布时间】:2010-06-29 19:31:07
【问题描述】:

我有一个纬度/经度值和距离值。我需要计算一个以给定位置为中心的边界框。所以如果距离是 200 米,那么矩形框应该是前后左右各 200 米。

如何使用 JavaScript 来做这件事?

【问题讨论】:

    标签: javascript math google-maps geolocation proj4js


    【解决方案1】:

    您需要将您的坐标 lat/long 转换为您正在使用的地图投影中的 x/y 值,然后您可以计算您的边界框。

    我不太了解 Google Maps API,也不知道你想用你的盒子做什么。但也许GBoundsGMercatorProjectionGLatLngBounds 会有所帮助。如果 Google Maps API 不支持您正在使用的地图投影的计算,那么使用 Proj4js 会很有帮助。也许你想了解Map projections。 Google 地图默认使用Mercator projection

    【讨论】:

      【解决方案2】:

      以下是一些用于处理纬度和经度的有用 javascript 函数:

      http://www.movable-type.co.uk/scripts/latlong.html

      对于一个点周围的边界框,使用the above javascript library 的简单修改可能是:

      LatLon.prototype.boundingBox = function (distance)
      {
          return [
              this.destinationPoint(-90, distance)._lon,
              this.destinationPoint(180, distance)._lat,
              this.destinationPoint(90, distance)._lon,
              this.destinationPoint(0, distance)._lat,
          ];
      }
      

      (这使用"Destination point given distance and bearing from start point" 计算。)

      【讨论】:

        【解决方案3】:

        如果您使用的是V3 API,则可以使用RectangleCircle。请参阅此博主的简要说明和示例:

        http://apitricks.blogspot.com/2010/02/rectangle-and-circle-of-v3.html

        【讨论】:

          猜你喜欢
          • 2023-03-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-07-30
          • 2019-09-05
          • 2011-04-10
          相关资源
          最近更新 更多