简体   繁体   English

如何计算两个位置的距离?

[英]How to calculate two location distance?

calculate two locations distance if distance is greater than 5 Kms you have to return true?计算两个位置的距离,如果距离大于 5 公里,您必须返回 true?

Plz help me,i am new to MapView.请帮助我,我是 MapView 的新手。

try this尝试这个

#import <CoreLocation/CoreLocation.h>

 CLLocation *locA = [[CLLocation alloc] initWithLatitude:lat1 longitude:long1];

 CLLocation *locB = [[CLLocation alloc] initWithLatitude:lat2 longitude:long2];

 CLLocationDistance distance = [locA distanceFromLocation:locB];

 //Distance in Meters

if((distance*1000)>5)
{
    //return true;
    // your coding
}

Assuming you have coordinates of the points.假设你有这些点的坐标。

CLLocation *locA = [[CLLocation alloc] initWithLatitude:lat1 longitude:long1];

 CLLocation *locB = [[CLLocation alloc] initWithLatitude:lat2 longitude:long2];

 CLLocationDistance distance = [locA distanceFromLocation:locB];

Also you need to #import <CoreLocation/CoreLocation.h> as mentioned by Dharmesh Dhorajiya您还需要#import <CoreLocation/CoreLocation.h>如 Dharmesh Dhorajiya 所述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 根据道路计算两个位置之间的距离 - Calculate distance between two location based on roads 如何计算用户移动时从用户位置到注释的距离 - How to calculate distance from user location to annotation when user moves 如何计算我当前位置和MapView中其他Pins之间的距离 - How to calculate the distance between my current location and other Pins in MapView 通过与其他位置的距离计算位置 - Calculate location by distance from other location 如何在iOS中通过Localsearch(搜索栏)计算当前位置与所选位置/目的地之间的距离 - How to calculate distance between current location and selected location/destination from Localsearch (search bar) in iOS ios - Spritekit - 如何计算两个节点之间的距离? - ios - Spritekit - How to calculate the distance between two nodes? 如何使用谷歌计算两个位置之间的距离 api in swift 4 - How to calculate distance between two locations using google api in swift 4 计算位置与位置列表之间的距离 - calculate distance between a location and a list of locations 计算用户位置与固定位置之间的距离 - Calculate distance between user's location and a fixed location 如何计算当前位置与JSON文件中填充的位置之间的距离 - How to calculate the distance between my current location and locations populated in a JSON File
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM