如何获取当前地图的当前区域,宽度和高度(相对于经度和纬度)? [英] How to get current Area, Width and Height (with respect to latitude and longitude) of current map?
本文介绍了如何获取当前地图的当前区域,宽度和高度(相对于经度和纬度)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我在 div
中有一个宽度 x
和高度 y的地图
具有t缩放级别。我如何找到当前可见的地图的面积,宽度和高度?
var spherical = google.maps.geometry.spherical,
bounds = map.getBounds(),
cor1 = bounds .getNorthEast(),
cor2 = bounds.getSouthWest(),
cor3 = new google.maps.LatLng(cor2.lat(),cor1.lng()),
cor4 = new google.maps.LatLng(cor1.lat(),cor2.lng()),
width = spherical.computeDistanceBetween(cor1,cor3),
height = spherical.computeDistanceBetween(cor1,cor4);
Let's say I have a map inside a div
with width x
and height y
with t zoom level. How can I find the area, width and height of the currently visible map?
解决方案
Here is the answer,
var spherical = google.maps.geometry.spherical,
bounds = map.getBounds(),
cor1 = bounds.getNorthEast(),
cor2 = bounds.getSouthWest(),
cor3 = new google.maps.LatLng(cor2.lat(), cor1.lng()),
cor4 = new google.maps.LatLng(cor1.lat(), cor2.lng()),
width = spherical.computeDistanceBetween(cor1,cor3),
height = spherical.computeDistanceBetween( cor1, cor4);
这篇关于如何获取当前地图的当前区域,宽度和高度(相对于经度和纬度)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文