如何在“Google静态地图”中计算距离 [英] How to calculate the distance in "Google static maps"

查看:94
本文介绍了如何在“Google静态地图”中计算距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我在windows窗体应用程序中使用谷歌静态地图

当我得到地图我设置中心点纬度,经度,缩放和图像大小

此代码计算的边界坐标

Hello
am use google static maps in my windows form app
when i get the map i set the center point "latitude,longitude" , zoom and image size
the boundaries coordinates calculated by this code

double scale = Math.Pow(2, m_intZoom);
NW_Latitude = CenterLat + (PicSizeY / 2) / scale;
NW_Longitude = CenterLon - (PicSizeX / 2) / scale;
NE_Longitude = CenterLon + (PicSizeX / 2) / scale;
WS_Latitude = CenterLat - (PicSizeY / 2) / scale;



现在

i找到了计算两个坐标之间距离的方法


Now
i found a way to calculate the distance between two coords

double earthR = 6371;

double deltaLat = 0;

double deltaLon = (m_dblLocationNWLongitude - m_dblLocationNELongitude) * Math.PI / 180;

double a = Math.Sin(deltaLat / 2) * Math.Sin(deltaLat / 2) +
            Math.Cos(m_dblLocationNWLatitude * Math.PI / 180) * Math.Cos(m_dblLocationNWLatitude * Math.PI / 180) *
            Math.Sin(deltaLon / 2) * Math.Sin(deltaLon / 2);
double b = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));

MapWidthDistance = earthR * b;
 ///////////////////////////
deltaLat = (m_dblLocationNWLatitude - m_dblLocationWSLatitude) * Math.PI / 180;

deltaLon = 0;

a = Math.Sin(deltaLat / 2) * Math.Sin(deltaLat / 2) +
     Math.Cos(m_dblLocationNWLatitude * Math.PI / 180) *
     Math.Cos(m_dblLocationNWLatitude * Math.PI / 180) *
     Math.Sin(deltaLon / 2) * Math.Sin(deltaLon / 2);

b = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));

MapHeightDistance = earthR * b;





但我觉得有什么不对,因为当我设置图像时尺寸为600x600

并计算我得到的距离MapWidthDistance!= MapHeightDistance

请注意地图所覆盖的区域很小并定义为正方形



任何建议或解决方案?



but i think there is something wrong because when i set the image size to 600x600
and calculate the distance i got MapWidthDistance != MapHeightDistance
note that the area covered in map is small and defined as a square

Any Suggestions or Solutions?

推荐答案

我使用中心点计算它

I calculate it by using the center point
double earthC = 6371000 * 2 * Math.PI;
double factor = Math.Pow(2, 8 + m_intZoomLevel);
double MeterPerPixel = (Math.Cos(CenterLat * Math.PI / 180) * earthC / factor)/2;
double MapWidthDistance = OrginalImageWidth * MeterPerPixel;
double ActualMeterPerPixel = MapWidthDistance / imgWidthAfterResize;


这篇关于如何在“Google静态地图”中计算距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆