谷歌地图半径

时间:2012-05-07 13:20:54

标签: javascript html html5 google-maps

我需要以km为单位找到谷歌地图半径(可见区域)。你能举个例子吗? 我试过了 `

var bounds = new google.maps.LatLngBounds();
var sw = bounds.getSouthWest(); 
var ne = bounds.getNorthEast();

var proximitymeter = google.maps.geometry.spherical.computeDistanceBetween (sw, ne);

`

但每次都返回相同的值

1 个答案:

答案 0 :(得分:1)

您正在寻找横截面距离。这将确定所显示地图的垂直和水平距离。

var bounds = new google.maps.LatLngBounds();
var sw = bounds.getSouthWest();
var ne = bounds.getNorthEast();
var east = new google.maps.LatLng(0, ne.lng());
var west = new google.maps.LatLng(0, sw.lng());
var north = new google.maps.LatLng(ne.lat(), 0);
var south = new google.maps.LatLng(sw.lat(), 0);
var width = google.maps.geometry.spherical.computeDistanceBetween(east, west);
var height = google.maps.geometry.spherical.computeDistanceBetween(north, south);

从这里你可以找到“半径”。