计算地图上两点距离 汇总

如何运用Python计算地图上两点的实际距离 作者:xxw9485 时间:2017/6/20 参考资料:参考资料1、参考资料2 之前遇到过这样的问题:手里有一批患者的具体居住地点以及对应的经纬度,我想分析下患者的具体分布情况,不同患者之间的距离关系,这时就需要根据某两点的经纬度来求该两点的实际距离了。下面就是计算公式和代码: 公式 球面上任意两点的距离计算公式可以参考维基百科上的下述文章。 Great-circle... 阅读详情

CLLocation的distanceFromLocation方法计算地图上距离 (汇总)

准备两个CLLocation的对象,比如要计算某个位置与使用者当前位置的距离,
则其 中一个CLLocation是userLocation = [locationManager location],locationManager是CLLocationManager的实例,
并已执行[locationManager startUpdatingLocation];
然后计算这两个CLLocation的距离(已格式化成12.34 km)
[NSString stringWithFormat:@"%0.2f km",
[userLocation distanceFromLocation :location]/1000]

 

根据经纬度计算两点之间距离的Obcective-C代码  

根据经纬度计算两点之间距离的Obcective-C代码,转自一位CocoaChina会员的博客(Link),
其中其中er 就是地球椭球半径,对于google map使用 6378137 就可以了。 函数的调用非常简单, 几乎适用任何平台:)

#define PI 3.1415926
double LantitudeLongitudeDist(double lon1,double lat1,
         double lon2,double lat2)
{
 double er = 6378137; // 6378700.0f;
 //ave. radius = 6371.315 (someone said more accurate is 6366.707)
 //equatorial radius = 6378.388
 //nautical mile = 1.15078
 double radlat1 = PI*lat1/180.0f;
 double radlat2 = PI*lat2/180.0f;
 //now long.
 double radlong1 = PI*lon1/180.0f;
 double radlong2 = PI*lon2/180.0f;
 if( radlat1 < 0 ) radlat1 = PI/2 + fabs(radlat1);// south
 if( radlat1 > 0 ) radlat1 = PI/2 - fabs(radlat1);// north
 if( radlong1 < 0 ) radlong1 = PI*2 - fabs(radlong1);//west
 if( radlat2 < 0 ) radlat2 = PI/2 + fabs(radlat2);// south
 if( radlat2 > 0 ) radlat2 = PI/2 - fabs(radlat2);// north
 if( radlong2 < 0 ) radlong2 = PI*2 - fabs(radlong2);// west
 //spherical coordinates x=r*cos(ag)sin(at), y=r*sin(ag)*sin(at), z=r*cos(at)
 //zero ag is up so reverse lat
 double x1 = er * cos(radlong1) * sin(radlat1);
 double y1 = er * sin(radlong1) * sin(radlat1);
 double z1 = er * cos(radlat1);
 double x2 = er * cos(radlong2) * sin(radlat2);
 double y2 = er * sin(radlong2) * sin(radlat2);
 double z2 = er * cos(radlat2);
 double d = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));
 //side, side, side, law of cosines and arccos
 double theta = acos((er*er+er*er-d*d)/(2*er*er));
 double dist  = theta*er;
 return dist;
}
复制代码
1:获取当前手机经纬度
@implementation CurrentLocation
@synthesize locationManager;
@synthesize target,callBack;

#pragma mark --
#pragma mark Public

-(void) startUpdatingLocation{

    [[self locationManager] startUpdatingLocation];

}

#pragma mark --
#pragma mark Memory management

-(void) dealloc{

    [super dealloc];

    [locationManager release];

}

#pragma mark --
#pragma mark Location manager

/*

 Return a location manager -- create one if necessary.

 */

- (CLLocationManager *)locationManager {

    if (locationManager != nil) {return locationManager;}

    locationManager = [[CLLocationManager alloc] init];

    [locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];

    [locationManager setDelegate:self];

    return locationManager;

}

#pragma mark --
#pragma mark CLLocationManagerDelegate methods

/*

 Conditionally enable the Add button:

 If the location manager is generating updates, then enable the button;

 If the location manager is failing, then disable the button.

 */

- (void)locationManager:(CLLocationManager *)manager

    didUpdateToLocation:(CLLocation *)newLocation

           fromLocation:(CLLocation *)oldLocation {

    NSLog(@"获取到经纬度!");

}

- (void)locationManager:(CLLocationManager *)manager

       didFailWithError:(NSError *)error {

        NSLog(@"获取失败!");

 }

@end


2:  获取当前手机经纬度的详细地址


@implementation AddressReverseGeoder

#pragma mark --
#pragma mark Public

//根据经纬度开始获取详细地址信息
- (void)startedReverseGeoderWithLatitude:(double)latitude longitude:(double)longitude{

    CLLocationCoordinate2D coordinate2D;

    coordinate2D.longitude = longitude;

    coordinate2D.latitude = latitude;

    //

    MKReverseGeocoder *geoCoder = [[MKReverseGeocoder alloc] initWithCoordinate:coordinate2D];

    geoCoder.delegate = self;

    [geoCoder start];

}

#pragma mark --
#pragma mark MKReverseGeocoderDelegate methods

//获得地址信息

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark {

    NSString *address = [NSString stringWithFormat:@"%@ %@ %@ %@ %@%@",

                                      placemark.country,

                                      placemark.administrativeArea,

                                      placemark.locality,

                                      placemark.subLocality,

                                      placemark.thoroughfare,

                                      placemark.subThoroughfare];

    NSLog(@"经纬度所对应的详细:%@", address);

    geocoder = nil;

}

//错误处理

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error {

    NSLog(@"error %@" , error);

}

#pragma mark --
#pragma mark Memory management

- (void)dealloc {

    [super dealloc];

}

@end
复制代码

The distance is calculated between 2 CLLocations and not between to coordinates.

You need to use these coordinates to get the CLLocations for the respective coordinates using the following line of code

CLLocation*newLocation =[[CLLocation alloc] initWithCoordinate: newCoordinate altitude:1 horizontalAccuracy:1 verticalAccuracy:-1 timestamp:nil];

Similarly for the other coordinate and then you can calculate the distance between these two locations using the following line of code

CLLocationDistance kilometers =[newLocation distanceFromLocation:oldLocation]/1000;



In MkMapview calculate distance between two points

问:

Hi in iPhone App How to calculate distance between two points in MKMapView as shown in image

first point would be center point of visible map in mapview

2nd point would be any of corner of visible rect of mapview in mapview(here for example i have taken top left point)

答:

You can get lat/lon of the center with:

convertPoint:toCoordinateFromView:

loc1 and loc2 are both CLLocation objs.

CLLocationDistance dist =[loc1 distanceFromLocation:loc2];

So these two tips should help you. if you need some code, let me know :-)

 

答:

Here is how you can calculate the wanted distance :

// You first have to get the corner point and convert it to a coordinate
MKMapRect mapRect = self.mapView.visibleMapRect;
MKMapPoint cornerPointNW =MKMapPointMake(mapRect.origin.x, mapRect.origin.y);
CLLocationCoordinate2D cornerCoordinate =MKCoordinateForMapPoint(cornerPointNW);

// Then get the center coordinate of the mapView (just a shortcut for convenience)
CLLocationCoordinate2D centerCoordinate = self.mapView.centerCoordinate

// And then calculate the distance
CLLocationDistance distance =[cornerCoordinate distanceFromLocation:centerCoordinate];


计算走过的距离,并显示出来
问:

I trying to calculate the total distance travelled and output it to the View Controller, but the results are not as expected. Code is as follows:

MyCLController.m

-(void)locationManager:(CLLocationManager*)manager
    didUpdateToLocation:(CLLocation*)newLocation
           fromLocation:(CLLocation*)oldLocation
{       
    validLocation = YES;

    if(!newLocation) 
    {
        validLocation = NO;
    }

    if(newLocation.horizontalAccuracy <0)
    {
        validLocation = NO;
    }

    // Filter out points that are out of order
    NSTimeInterval secondsSinceLastPoint =-[newLocation.timestamp timeIntervalSinceNow];
    if(secondsSinceLastPoint <0)
    {
        validLocation = NO;
    }

    if(validLocation == YES)
    {
        [self.delegate locationChange:newLocation :oldLocation];
    }

NewWorkoutViewController.m

-(void)locationChange:(CLLocation*)newLocation:(CLLocation*)oldLocation
{       

    CLLocationDistance meters =[newLocation distanceFromLocation:oldLocation];

    currentSpeed =([newLocation speed]*3600)/1000;
    totalDistance =(totalDistance + meters)/1000;
    totalDistanceMeters =  totalDistanceMeters + meters;
    avgSpeed = totalDistance / counterInt;

    [speedLbl1 setText:[NSString stringWithFormat:@"%.3f", currentSpeed]];
    [distanceLbl1 setText:[NSString stringWithFormat:@"%.3f", totalDistance]];

}

The problem is with my totalDistance, it doesn't appear to be adding to it each time, its as if its overwriting it, when I test in the car I can see values of 10 / 20 meters between coordinates, so this indicates that distanceFromLocation appears to be working.

Anyone any thoughts ?


答:

Try this :

totalDistance = totalDistance +(meters /1000);

instead of this

totalDistance =(totalDistance + meters)/1000;

The way you had it, totalDistance was being divided by 1000 each time i.e. if you're travelling 10m each time :

totalDistance =(0+10)/1000=0.01;
totalDistance =(0.01+10)/1000=0.01001//!< You expected this to be 0.02!
totalDistance =(0.01001+10)/1000=0.01001001//!< You expected this to be 0.03!

如何计算地球任意两点之间距离 theme: jzman jvideo 相关源码和模型的下载链接地址点击链接进行跳转 前言 本文通过百度地图api实现一个地球地图模型,通过运用精确的Haversine公式和Vincenty公式,系统能够迅速计算出这两个坐标点之间的实际距离。文中力求使用专业的地理和数学的术语解释计算原理,如有失误,请指正,谢谢 技术栈 typescript 百度地图api vite 加载地图... 阅读详情

相关推荐

基于百度地图API计算任意两点间的出行距离

文章目录前言使用步骤1.导入相关包2.计算小汽车距离3.计算骑行距离4.创建主函数总结 前言 为了方便自己以后查找代码,也不想让自己的桌面变得凌乱不堪,所以将把自己之前的代码保存到这里面。 之前做项目时候,遇到了以下问题:对于任意两点间的地理坐标(火星坐标系),怎样计算其距离? 数据示例如下: 最终基于百度API搞定了这个问题,下面是相关思路和代码。 使用步骤 首先我们需要自己去百度地图api官网上申请注册自己的key,网址:https://lbsyun.baidu.com/ 1.导入相关包 impo

qq_41227847的博客 5696

CLLocation的distanceFromLocation方法计算地图上距离 (汇总)

准备两个CLLocation的对象,比如要计算某个位置与使用者当前位置的距离,则其 中一个CLLocation是userLocation = [locationManager location],locationManager是CLLocationManager的实例,并已执行[locationManager startUpdatingLocation];然后计算这两个CLLocation的距离(...

weixin_34162695的博客 389

如何用python绘制地图并计算地图上两点之间的距离【附源码】

一、这段代码用plotiy库绘制了可视化世界平面地图,计算了纽约和洛杉矶两个城市之间的距离,并将其打印输出。二、还有一个方法可以实现该功能,使用folium库实现可视化世界平面地图,添加了纽约和洛杉矶两个城市的坐标点,并在地图上显示。text=['New York', 'Los Angeles'], # 标注文本。print("纽约和洛杉矶之间的距离:", distance, "公里")print("纽约和洛杉矶之间的距离:", distance, "公里")计算了这两个城市之间的距离,并将其打印输出。

helloshili2011的博客 1194

地图定位CLLocation详解

1. distanceFromLocation: 方法 /* * distanceFromLocation: * * Discussion: * Returns the lateral distance between two locations. */ - (CLLocationDistance)distanceFromLocation:(const CLLocat

Walden_tinghou的专栏 8530

根据经纬度获取两点之间的距离 -- 腾讯地图(PHP后台)

项目需求:根据经纬度获取两点之间的距离,我这里用的是腾讯地图的api php代码: /** * 利用腾讯地图api * 计算两点地理坐标之间的距离 */ function getDistance(){ $key = '填写你的key'; //腾讯地图开发自己申请 $mode = 'driving'; //driving(驾车)、walking(步行) $from = '填写你的起点坐标'; //例如:39.14122,117.14428 $to = '起点坐标;终点坐标';

马冠亚的博客 3万+

微信小程序 计算两点及多点间的距离+选择地图定位

本文基于腾讯地图开发文档实现此功能 1.首先去腾讯地图开发平台注册,申请自己的应用空间,严格按照以下步骤走完 2.把下载的两个sdk包,放在小程序utils **3.接下来就可以正常使用了 (这是计算多点距离) wxml <form bindsubmit="formSubmitone"> <label>终点坐标: <input style="border:1px solid #000;" name="dest"></input>

qq_34913864的博客 6483

iOS CLLocation对象详解

一、简介 作用:用来表示某个位置的地理信息,比如经纬度、海拔等等 常用属性 // 经纬度 @property(readonly,nonatomic)CLLocationCoordinate2Dcoordinate; // 海拔 @property(readonly,nonatomic)CLLocationDistance altitude; // 路线,航向(取值范围是0.0°~359.9

Lea__DongYang的博客 1422

35.(leaflet篇)leaflet+turf计算离点距离最近线上的点坐标.zip

下载如有问题,可私信博主。下载前建议先查看博客内容,其地址为:https://blog.youkuaiyun.com/QQ98281642/article/details/120341546

计算地图上两点距离

参考:https://blog.youkuaiyun.com/pyx6119822/article/details/52298037 # coding: utf-8 import math # 参看:http://blog.youkuaiyun.com/zengmingen/article/details/68490497 # 大地坐标系资料WGS-84 长半径a=6378137 短半径b=6356752.3142...

wyBluewind的博客 2318

DQN网络代码调用env.reset()后存储观测信息报错问题ValueError: setting an array element with a sequence.解决处理

**reset()函数返回的是一个array类型以及其中数据的type!模拟游戏进行学习任务。因此需要将observation指定为真正需要的array信息即可,得到的的变量observation类型与Agent存储时的。因此怀疑返回的observation有问题,于是通过。报错信息提示为数据维度不对应,也即最初通过。在强化学习DQN网络代码实现过程中,针对。

Vulcan_Q的博客 4092

从原理到实现:在《图灵完备》中构建一个144*256像素、1536时钟刻/帧的视频播放器

本文详细解析了在《图灵完备》游戏中构建144*256像素、1536时钟刻/帧视频播放器的全过程。从图灵完备原理出发,通过分层架构设计、视频数据预处理和关键电路实现,展示了如何用基础电子元件模拟现代显卡功能。重点介绍了像素坐标定位系统和颜色数据处理流水线的优化方案,为游戏内复杂电子系统设计提供实践指导。

weixin_42520025的博客 445

通过高德地图API取得两点坐标间的距离

高德地图在取两点间的距离比百度地图更详细,可以分为几种类型的API,提供的步行、公交、驾车查询。今天咱们使用驾车的API来计算两点的距离。其它的API大同小异。1. 高德地图提供了更详细的距离查询API,包括步行、公交和驾车等多种方式。2. 该API使用GET请求,需要传入起点和终点坐标,ak开发者key以及output输出格式等参数。4. 代码示例展示了如何发送请求,接收响应,并解析JSON数据来获取驾车距离(单位为米)。6. 如果参数顺序错误,可能会得到20000等错误码,需要注意参数的正确性。

heweiyabeijing的专栏 4439

Matlab实战:水声信号DEMON谱分析从入门到精通(附完整源码)

本文详细介绍了使用Matlab进行水声信号DEMON谱分析的完整流程,从基础理论到实战应用,涵盖信号预处理、包络提取、频谱分析等关键步骤,并附完整源码。特别针对水声通信中的低信噪比环境,提供了多种优化方案和性能提升技巧,帮助读者快速掌握这一水下目标检测的核心技术。

gamma的博客 295

ArcGIS Engine -- 常用方法

空间关系 计算两点间距离 1 /// <summary>计算两点间距离2 /// </summary>3 /// <param name="point1"></param>4 /// <param name="point2"></param>5 /// <returns></retur...

weixin_30781107的博客 170

ubuntu20.04 终端安装claude

【代码】ubuntu20.04 终端安装claude。

hongliyu_lvliyu的博客 2589

ADBC 全面解析:ABAP 开发者玩转 Native SQL 的实战指南

本文介绍了 SAP ABAP 中的 ADBC(ABAP Database Connectivity)技术,它是一种基于 ABAP 面向对象的类库,用于访问 Native SQL 接口。与 Open SQL 和 EXEC SQL 相比,ADBC 具有以下优势:支持特定数据库语法、可访问二级数据库连接、执行多种 SQL 操作且语法更 ABAP 化。文章通过示例展示了 ADBC 的基本用法,包括创建语句对象、执行查询和处理结果集。建议在需要数据库特有功能或二级连接时优先使用 ADBC,同时提供封装类来简化调用。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 305

腾讯地图计算两点间距离

上一篇没来得及说,之所以把百度地图换成腾讯地图,是因为在IOS中,小程序不能正确显示,具体出错如下图(我真是费老大劲找出来的),网上百度了好多,也有出现类似情况的,心痛,在小程序官方也没找到解决方案,若有人知道,望周知,定感激不尽。 换成腾讯地图后,出现定位偏差,而且而且,偏差很大,老板在濮阳,竟然显示的是上海,好吧,他过年的时候在上海。没办法,还是换成了H5定位。 具体的H5定位,已经在...

ansheng02的博客 1万+

【PointNet++】使用Open3D对分割后的结果可视化

PointNet++中的局部分割网络预测后是没有可视化文件的,所以需要自己通过编写Open3D或者PCL点云算法去可视化,在本人经过查找翻阅修改后,实现了网络输出点云分割后结果的可视化。已实现推测单个点云,并可视化。

纵马踏花向自由 2453

调用腾讯地图接口计算两点之间距离

计算点到点之间的距离 示例: 计算用户到任意一个门店的距离 代码仅供参考: <?php public function distince() { //接收用户当前的经纬度,门店的id $params['latLng'] = $this->request->input('latLng');//用户当前位置所在的经纬度 $params['shop_id'] = $this->request->input('shop_id');//目标门店的id

Bug_Curry的博客 3100

诊断CAPL自动化(5) ——没有CANdela,无法编辑cdd数据库文件,也能轻松完成诊断测试

🍅我们知道cdd数据库文件,是CANoe测试环境的重要组件,它可以让我们更加轻松的完成诊断测试工作;但是创建和编辑cdd文件是需要CANdela 来完成的,一个 liscense 就要将近二十万,成本确实高🍅特别是在处理22/2E/31服务的时候,频繁的增加功能,可能需要频繁的用CANdela 修改CDD,我测试开发过程中,一般很少去修改cdd,有这个时间,纯手撸也开发完了,就一个CANdela,鬼知道此时此刻到了谁手里,我也懒得去找。🍅演示软硬件环境;目录📘前言。

蚂蚁小兵 5756

2024年广东省职业院校技能大赛“区块链技术应用”任务书—区块链应用系统开发参考答案

摘要 本文档提供了2024年广东省职业院校技能大赛"区块链技术应用"项目中区块链电子签章前端功能开发的参考答案。主要内容包括:1)注册页面开发,实现身份证号码双向绑定和注册请求发送;2)登录页面开发,实现用户认证、状态保存和页面跳转;3)个人印章页面开发,实现注销功能和印章信息展示。每个任务均包含具体实现代码片段和功能测试要点,涵盖Vue.js框架下的数据绑定、axios请求处理和本地存储等关键技术点。

我是网络安全兼技能大赛工程师,专注网络安全技术学习与技能大赛实战!持续分享最新的技术文章,帮你少走弯路,一起在技术赛道上进步~ 343

使用百度地图API计算两点直线距离、道路距离和行车时间

使用百度地图API计算两点直线距离、道路距离和行车时间摘要关键词介绍数据展示新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入 摘要 在本篇博客中,将通过调用百度地图的API计算两点间的距离和行车时间。处理的csv文件包含30

qq_43325570的博客 9851

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

高德地图两点间距离计算函数

高德地图其实提供了计算接口,但是很多时候调用很不方便。 高德地图提供的计算距离示例计算结果如下: 用与上例相同的坐标使用计算距离的函数计算,结果如下: 两者相差无几,取整后所得数值一致,所以可以认为这个计算函数就是高德用来计算两点距离的函数。 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <script

D_lunar的博客 5893

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

高德地图之周边搜索及两点间距离计算(Poi的使用)

最近比较闲,所以就顺便研究高德地图,原因是之前基本上都用的百度地图,但是百度地图的代码太多了,两字,很烦。先来个效果图: 蓝色的marker就是点击的,蓝色的圆圈是我当前位置。 apk下载地址:http://download.youkuaiyun.com/detail/hedong_77/9731739 一些基本操作这里就不多说了,自己去看官方文档,我们这里说一下周边搜索和POI计算距离。 首先

Hedong的博客 2万+

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

python根据经纬度计算两点之间距离

两种方法,一个是利用python库,另一个利用math函数计算,最后和百度地图测量的做对比 计算结果 447.249799354 446.72072701 447.02 百度地图测量 # 1. Python 库 from geopy.distance import geodesic aa = geodesic((30.28708, 120.12802999999997), (28.7427, 115.86572000000001)).km # print(aa) # 2. 函数计算 fro

qq_43887455的博客 9805

百度地图API开发:map.getDistance计算两点之间的距离(直线距离)

getDistance(start: Point, end: Point),返回两点之间的距离,单位是米 创建容器 <div id="container"></div> JS代码 //异步加载地图 function loadJScript() { var script = document.createElement('script'); script.type = 'text/javascript'; scrip.

挖掘大数据价值,让决策者快速洞悉趋势,让大众读懂数据背后的故事。 6409
上一篇: NSDate与NSDateFormatter
下一篇: MySQL 加锁策略
focusjava
博客等级 码龄14年 127粉丝 528原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值