计算地图上两点距离 汇总

如何运用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的博客 5700

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的博客 1195

地图定位CLLocation详解

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

Walden_tinghou的专栏 8531

根据经纬度获取两点之间的距离 -- 腾讯地图(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的博客 6487

iOS CLLocation对象详解

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

Lea__DongYang的博客 1424

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

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

计算地图上两点距离

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

wyBluewind的博客 2318

eCognition易康面向对象分类批量选择样本,批量导出shp

可以的,使用这个工具条最右边那个三角尺manual editing toolbar,这是用来直接指定类别的,咱们可以拿它选完以后把指定的类别转成训练样本。另一个好处是,这个选出来的样本可以直接导出成shp,但select sample是不可以的,只能导出TTAMask也就是栅格掩膜。如果要导出shp,要在转之前导出。中间那条有点点的红线就是我的鼠标轨迹,只要碰到的对象就会全部选中,然后一点3的那个按钮就直接全部划分为林地了,十分丝滑。在弹出来的工作条里,首先选择你的类别,比如这里选一个forest。

qq_61845364的博客 4074

TouchGFX在STM32上的移植全过程:超详细版指南

深入讲解将TouchGFX集成到STM32开发环境的每一步,涵盖配置、驱动适配与UI调试。无论是初学者还是进阶开发者,都能快速掌握TouchGFX在嵌入式平台的应用技巧。

weixin_42443533的博客 606

基于百度地图api的移动路径绘制以及距离计算

以下代码能够在地图上绘制自己走过的路径,有一个计时器,一个路程显示。按下“开始跑步”就可以开始绘制轨迹并同时开始计时。 以下是MainActivity文件 public class MainActivity extends Activity { // int count=-0; MapView mMapView = null; LocationClient mLocCl...

songbinxu的博客 1万+

MoveIt避障规划实战:从点云到OctoMap的环境感知全流程

本文详细解析了MoveIt避障规划中从点云到OctoMap的环境感知全流程,重点介绍了深度相机选型、点云数据处理、OctoMap生成及避障规划参数调优等关键技术。通过实战案例展示了如何利用MoveIt和OctoMap实现机械臂在复杂环境中的高效避障,为工业自动化和服务机器人开发提供实用解决方案。

weixin_30417487的博客 570

ArcGIS Engine -- 常用方法

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

weixin_30781107的博客 171

小米万兆路由器里的Docker安装可道云(Kodexplorer)私有网盘

小米2022年12月份发布了万兆路由器,里面可以使用Docker。 今天尝试在小米的万兆路由器里安装[可道云](http://kodcloud.com/)(Kodexplorer)私有网盘。

engchina的专栏 1万+

orangepi 5 plus ubuntu24.04上安装redroid

OrangePi 5 Plus运行reDroid云手机方案总结 在RK3588+Ubuntu 24.04上部署reDroid(Android容器化方案)的关键步骤: 内核要求:确保启用binderfs(无需ashmem,新版reDroid使用memfd替代); 安装流程: 安装Docker并配置代理加速镜像拉取; 拉取reDroid镜像(推荐Android 12/13 ARM64版本); 通过挂载binderfs启动容器,指定分辨率与DPI参数; 多实例管理: 脚本化创建多个容器(如8个实例),分配独立端口

babytiger的专栏 2310

腾讯地图计算两点间距离

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

ansheng02的博客 1万+

PoP(Package on Package)封装技术探讨

PoP(Package on Package)封装技术摘要 PoP是一种3D封装技术,通过垂直堆叠已完成封装的器件(如SoC+DRAM)实现高密度集成,典型应用于智能手机等空间受限场景。其核心优势包括:节省主板面积(垂直堆叠)、优化高速信号完整性(短互连路径)、提升供应链灵活性(独立测试与选型)。PoP结构分为底封装(通常为Flip-Chip BGA的SoC)和顶封装(如FBGA存储芯片),通过焊球阵列互连,一次回流焊完成组装。

sinat_15150363的博客 386

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

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

Bug_Curry的博客 3101

Python爬虫实战:高效爬取CNKI知网文献数据的技术解析

本文将详细介绍如何使用Python最新技术构建一个高效的CNKI知网文献爬虫系统。我们将从爬虫基础知识讲起,逐步深入到高级反反爬技术、分布式爬取、智能解析等前沿内容。文章包含完整的代码实现,涵盖请求模拟、数据解析、持久化存储等关键环节,并特别针对CNKI的反爬机制提供解决方案。通过本文,读者将掌握构建专业级学术文献爬虫的全套技术栈。关键词:Python爬虫、CNKI爬取、反反爬技术、文献数据挖掘、Scrapy框架本文详细介绍了如何使用Python最新技术构建CNKI知网文献爬虫。

2201_76125261的博客 2078

基于Matlab的深度学习OFDM系统信号检测

在接收端,我们首先去除循环前缀,然后对接收到的信号进行FFT变换和QAM解调。在通信系统中,正交频分复用(Orthogonal Frequency Division Multiplexing,OFDM)是一种常用的调制技术,它可以将高速数据流分成若干个低速子载波进行传输,提高了信道利用率和抗干扰性能。接下来,我们使用训练好的神经网络对QAM调制后的数据进行检测,得到估计的FFT变换结果。深度学习方法可以通过大量的训练数据来学习信号的特征,并具有一定的适应能力,在某些情况下可能能够获得更好的检测性能。

2301_79325657的博客 299

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

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

qq_43325570的博客 9859

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

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

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

D_lunar的博客 5895

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

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

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

Hedong的博客 2万+

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

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的博客 9806

百度地图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.

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

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址