![](/img/trans.png)
[英]Calculating bounding box using getBoundingClientRect() Issue with swift top, left
[英]Calculating the bounding box using Javascript
我有緯度/經度值和距離值。 我需要計算一個以給定位置為中心的邊界框。 所以如果距離是200米那么矩形框應該在前面,后面,左邊和右邊200米。
我如何使用JavaScript進行此操作?
您需要將坐標lat / long轉換為您正在使用的地圖投影中的ax / y值,然后您可以計算邊界框。
我不太了解谷歌地圖API,我也不知道你想要用你的盒子做什么。 但也許GBounds , GMercatorProjection和GLatLngBounds可能會有所幫助。 如果Google Maps API不支持您正在使用的地圖投影的計算,那么使用Proj4js會很有幫助。 也許你想了解一下Map投影 。 默認情況下,Google地圖使用墨卡托投影 。
以下是一些用於處理緯度和經度的有用的javascript函數:
http://www.movable-type.co.uk/scripts/latlong.html
對於一個點周圍的邊界框,使用上述javascript庫的簡單修改可能是:
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,
];
}
(這使用“目的地點給定距離和起點承載”計算。)
如果您使用的是V3 API ,則可以使用矩形和圓形 。 請參閱此博主的簡要說明和示例:
http://apitricks.blogspot.com/2010/02/rectangle-and-circle-of-v3.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.