Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/414.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用中心坐标、宽度和高度查找google地图的边界坐标_Javascript_Google Maps - Fatal编程技术网

Javascript 如何使用中心坐标、宽度和高度查找google地图的边界坐标

Javascript 如何使用中心坐标、宽度和高度查找google地图的边界坐标,javascript,google-maps,Javascript,Google Maps,假设我有一个中心坐标(1.222222,2.3333),宽25公里,高12公里。 从这里我想找到具有指定中心的边界点打开选项是使用 代码片段: html, 身体, #地图{ 宽度:100%; 身高:100%; 填充:0px; 边际:0px; } 函数initMap(){ 变量高度=12000;//m 变量宽度=25000;//m var center=newgoogle.maps.LatLng(1.22222,2.3333); var bounds=new google.maps.LatL

假设我有一个中心坐标(1.222222,2.3333),宽25公里,高12公里。 从这里我想找到具有指定中心的边界点

打开选项是使用

代码片段:

html,
身体,
#地图{
宽度:100%;
身高:100%;
填充:0px;
边际:0px;
}

函数initMap(){
变量高度=12000;//m
变量宽度=25000;//m
var center=newgoogle.maps.LatLng(1.22222,2.3333);
var bounds=new google.maps.LatLngBounds();
var top=google.maps.geometry.spheremic.computeOffset(中心,高度/2,0);
var bottom=google.maps.geometry.spheremic.computeOffset(中心,高度/2180);
var left=google.maps.geometry.spheremic.computeOffset(中心,宽度/2,-90);
var right=google.maps.geometry.spheremic.computeOffset(中心,宽度/2,90);
扩展(顶部);
边界。延伸(左);
边界。扩展(底部);
边界。扩展(右);
var map=new google.maps.map(document.getElementById('map'){
中心:中心,,
缩放:2,
mapTypeId:'地形'
});
var centerMarker=new google.maps.Marker({
地图:地图,
位置:中
})
var rect=new google.maps.Rectangle({
地图:地图,
界限:界限
});
映射边界(bounds);
}

如何将上述设置为地图边界并转到缩放级别以将其作为边界?这听起来像是另一个问题(您需要动态调整地图div的大小以实现这一点)
var height = 12000; // m
var width = 25000; // m
var center = new google.maps.LatLng(1.22222, 2.3333);
var bounds = new google.maps.LatLngBounds();
var top = google.maps.geometry.spherical.computeOffset(center, height / 2, 0);
var bottom = google.maps.geometry.spherical.computeOffset(center, height / 2, 180);
var left = google.maps.geometry.spherical.computeOffset(center, width / 2, -90);
var right = google.maps.geometry.spherical.computeOffset(center, width / 2, 90);
bounds.extend(top);
bounds.extend(left);
bounds.extend(bottom);
bounds.extend(right);