如何计算 Google 静态地图图像的缩放比例
我目前正在使用 Google 静态地图图像,我希望了解如何计算给定缩放级别的比例。我知道谷歌地图使用墨卡托投影。我正在制作的应用程序从 Google 获取卫星地图图像,用户在其顶部绘制一个多边形。我需要以现实世界单位计算该多边形的面积。有什么建议吗???
I am currently working with Google Static maps images and i wish to find out how to calculate the scale for a given zoom level. I know Google maps use Mercator Projections. The application I am making gets a satellite map image from the Google and a user draws a polygon on top of it. I need to calculate the area of this polygon in real world units. Any suggestions???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如 Google 地图文档所述:
这意味着在缩放级别 2 时,地图任意方向的像素 = 256 * 2² = 1024px。
考虑到地球周长约为 40,000 公里,在变焦 0 时,每个像素 ~= 40,000 公里/256 = 156.25 公里
在变焦 9 时,像素为 131072:1px = 40,000 km / 131072 = 0.305 km ...等等。
如果我们想要 400px = 1km,我们必须选择最接近的近似值,因此: 1px = 1km/400 = 0.0025km
我尝试了 Zoom = 15 并获得了 1px = 0.00478 和 Zoom = 16 给了我 1px = 0.00238km
这意味着你应该使用zoom = 16,那么你每次将有0.955公里400 像素在赤道线上并且仅适用于x 坐标。
当你在纬度上向北或向南移动时,周长每次都会变小,从而改变距离。当然,它也会改变y 轴的相关性,因为球体的投影很棘手。
如果您想使用函数计算精确距离,则应使用 Google 提供的函数 他们的文档:
As stated at Google Maps Documentation:
Meaning that at zoomLevel 2,the pixels in any direction of a map are = 256 * 2² = 1024px.
Taking into account that the earth has a perimeter of ~40,000 kilometers, in zoom 0, every pixel ~= 40,000 km/256 = 156.25 km
At zoom 9, pixels are 131072: 1px = 40,000 km / 131072 = 0.305 km ... and so on.
If we want 400px = 1km, we have to choose the closest approximation possible, so: 1px = 1km/400 = 0.0025km
I tried zoom = 15 and obtained 1px = 0.00478 and zoom = 16 that gave me 1px = 0.00238km
Meaning that you should use zoom = 16, and you will have 0.955km every 400px in the Equator line and only for x coordinates.
As you go north or south in latitude, perimeter is everytime smaller, thus changing the distance. And of course it also changes the correlation in the y axis as the projection of a sphere is tricky.
If you want to calculate with a function the exact distance, you should use the one provided by Google at their documentation:
你可以试试这个:
You can try this: