13
可視地圖半徑怎樣才能找到我的地圖的可視區域的接近?谷歌地圖V3 - 英里
這一切工作和爲柱,以幫助其他人誰可能會尋找。
此代碼通過VAR接近看你的谷歌地圖V3和輸出在當前地圖視圖英里半徑。
確保在你的HTML你有
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true&libraries=geometry"></script>
爲庫=幾何啓用它。
// Get Gmap radius/proximity start
var bounds = new google.maps.LatLngBounds();
var sw = bounds.getSouthWest();
var ne = bounds.getNorthEast();
var proximitymeter = google.maps.geometry.spherical.computeDistanceBetween (sw, ne);
var proximitymiles = proximitymeter * 0.000621371192;
alert(" " + proximitymiles + " Miles Proximity");
var proxmity = proximitymiles;
// Get Gmap radius/proximity End
我希望它可以幫助別人。
附加的編輯(未測試),其允許屏幕旋轉如下:
// Get Gmap radius/proximity start
var bounds = new google.maps.LatLngBounds();
var sw = bounds.getSouthWest();
var ne = bounds.getNorthEast();
var se = bounds.getSouthEast();
var nw = bounds.getNorthWest();
var proximitymeterswne = google.maps.geometry.spherical.computeDistanceBetween (sw, ne);
var proximitymetersenw = google.maps.geometry.spherical.computeDistanceBetween (se, nw);
if (proximitymeterswne > proximitymetersenw) {proximitymeterswne = proximitymiles}
else {if (proximitymetersenw > proximitymeterswne) {proximitymetersenw = proximitymiles};};
var proximitymiles = proximitymeter * 0.000621371192;
alert(" " + proximitymiles + " Miles Proximity");
var proxmity = proximitymiles;
// Get Gmap radius/proximity End
另一個EDIT
// Watches for map bounds change - if so - set radius and refresh data Start
function setproximityfrommap() {
// http://stackoverflow.com/questions/3525670/radius-of-viewable-region-in-google-maps-v3
// Get Gmap radius/proximity start
var bounds = new google.maps.LatLngBounds();
// bounds = map.LatLngBounds();
//center = new google.maps.LatLng();
ne = bounds.getNorthEast();
center = map.getCenter();
//var center = map.LatLngBounds.getCenter();
//var ne = map.LatLngBounds.getNorthEast();
// r = radius of the earth in statute miles
var r = 3963.0;
// Convert lat or lng from decimal degrees into radians (divide by 57.2958)
var lat1 = center.lat()/57.2958;
var lon1 = center.lng()/57.2958;
var lat2 = ne.lat()/57.2958;
var lon2 = ne.lng()/57.2958;
// distance = circle radius from center to Northeast corner of bounds
proximity = r * Math.acos(Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1));
$('#proximity').val(proximity);
// Get Gmap radius/proximity End
};
我把編輯的代碼在第一個柱。
人族
+1我喜歡你的慷慨的做法!但是,爲了保持網站的問答風格,我建議你將問題和解決方案的目標作爲答案發布,然後接受它(即使它是你的)。感謝;) – bluish 2012-02-03 07:59:26
謝謝 - 我會做 - 不是肯定的是什麼eticate是;) – 2012-02-03 12:25:50
我可以添加使用其他角落的檢查做,因爲這是在手機上的應用程序,它可以左右轉動(定向明智)爲好。根據以最大數字作爲接近度的讀數。 – 2012-02-03 12:31:15