두 곳 사이의 거리를 계산하는 방법은 무엇입니까? iPhone 용 Google지도에서 사용할 수있는 서비스가 있습니까?

StackOverflow https://stackoverflow.com/questions/1643138

  •  10-07-2019
  •  | 
  •  

문제

사용자가 선택한 두 곳 사이에 거리를 표시하도록 시설을 배치하고 싶습니다.

그렇게 할 수있는 샘플 소스 코드 / 서비스가 있습니까?

미리 감사드립니다.

도움이 되었습니까?

해결책

그만큼 Corelocation 프레임 워크 두 지점 사이에서 거리를 미터로 해결할 수있는 기능을 제공합니다.

- (CLLocationDistance)getDistanceFrom:(const CLLocation *)location

초기화 할 수 있습니다 CLLocation 위도와 경도가있는 물체 :

- (id)initWithLatitude:(CLLocationDegrees)latitude longitude:(CLLocationDegrees)longitude

다른 팁

두 개의 cllocation 객체가있는 경우 다음을 수행 할 수 있습니다.

[location1 getDistanceFrom:location2];

그러나 그것은 단지 지점에서 지점 일뿐입니다. 특정 경로에서 거리를 원한다면, 그것은 완전히 다른 물고기 주전자입니다.

이것은 cllocation 프레임 워크의 작업입니다. 2 점의 알려진 좌표를 사용하면 2 개의 Cllocation 객체를 만들 수 있으며 사용하는 거리를 찾을 수 있습니다.

- (CLLocationDistance)getDistanceFrom:(const CLLocation *)location

방법.

iPhone 개발에 익숙하지는 않지만 여기에는 Haversine 공식을 사용하여 두 지점 사이의 거리를 계산하기위한 C# 코드가 있습니다.

/// <summary>
/// Computes the distance beween two points
/// </summary>
/// <param name="P1_Latitude">Latitude of first point (in radians).</param>
/// <param name="P1_Longitude">Longitude of first point(in radians).</param>
/// <param name="P2_Latitude">Latitude of second point (in radians).</param>
/// <param name="P2_Longitude">Longitude of second point (in radians).</param>
protected double ComputeDistance(double P1_Longitude, double P1_Latitude, double P2_Longitude, double P2_Latitude, MeasurementUnit unit)
{            
    double dLon = P1_Longitude - P2_Longitude;
    double dLat = P1_Latitude - P2_Latitude;

    double a = Math.Pow(Math.Sin(dLat / 2.0), 2) +
            Math.Cos(P1_Latitude) *
            Math.Cos(P2_Latitude) *
            Math.Pow(Math.Sin(dLon / 2.0), 2.0);

    double c = 2 * Math.Asin(Math.Min(1.0, Math.Sqrt(a)));
    double d = (unit == MeasurementUnit.Miles ? 3956 : 6367) * c;
    return d;

}

측정 단위는 다음과 같이 정의됩니다.

/// <summary>
/// Measurement units
/// </summary>
public enum MeasurementUnit
{
    Miles,
    Kilometers
}

그것은 두 지점 사이에 어떤 종류의 차이를 갖고 있는지에 달려 있습니다. 지도에서 나는 당신이 공기 거리를 원하지 않는다고 생각합니다. 그런 다음 확인해야합니다 http://iosboilerplate.com/

여전히 공기 거리를 사용하고 싶다면 핵심 위치를 사용하십시오.

- (CLLocationDistance)getDistanceFrom:(const CLLocation *)location

수신기 위치에서 지정된 위치로 거리를 반환합니다. (iOS 3.2에서 더 이상 사용되지 않는다. 거리 프롬로 위치 사용 :

- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top