gpt4 book ai didi

javascript - Google map v3 - 以英里为单位的可视 map 半径

转载 作者:技术小花猫 更新时间:2023-10-29 12:27:03 25 4
gpt4 key购买 nike

如何找到 map 可见区域的邻近度?

所有这些都有效,并且是一个可以帮助其他可能正在寻找的人的帖子。

此代码查看您的 Google Map v3 并通过 var proximity 输出当前 map View 的半径(以英里为单位)。

确保在你的 HTML 中有

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true&libraries=geometry"></script>

因为 libraries=geometry 启用它。

// 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

另一个编辑

// 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
};

我把编辑好的代码放在第一篇文章中。

人族

最佳答案

// 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
// First, determine the map bounds
var bounds = map.getBounds();

// Then the points
var swPoint = bounds.getSouthWest();
var nePoint = bounds.getNorthEast();

// Now, each individual coordinate
var swLat = swPoint.lat();
var swLng = swPoint.lng();
var neLat = nePoint.lat();
var neLng = nePoint.lng();

var proximitymeter = google.maps.geometry.spherical.computeDistanceBetween(swPoint, nePoint);
var proximitymiles = proximitymeter * 0.000621371192;
proxmity = proximitymiles;
console.log("Proxmity " + proximitymiles + " miles");
}

关于javascript - Google map v3 - 以英里为单位的可视 map 半径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9121883/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com