Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6559697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:21:46+00:00 2026-05-25T13:21:46+00:00

I am trying to calculate the distance between two points (Pins) on the iPhone

  • 0

I am trying to calculate the distance between two points (Pins) on the iPhone map.
Everything works fine however if you put one of the pin close to the left edge and the other one to the right edge of the map, distanceFromLocation method always returned the shortest distance between points (of course earth is not flat). I tried switching the CLLocations but it still shows me the shortest distance.

For my app I will need to calculate both, shortest and the longest distance between two pins.
The problem seems to be trivial but I can’t come out with anything to solve it.
Any help or clues appreciated. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:21:46+00:00Added an answer on May 25, 2026 at 1:21 pm

    There is a function MKCoordinateRegionForMapRect that returns a MKCoordinateRegion. Without having tried it, seems like all you would need to do is accurately specify the rect as the region bounded at one diagonal by one pin and the other diagonal by the other pin. You could use CGRectUnion twice giving the pin origins as rect origin and an arbitrarily small width and height.

    Then the distance between the pins will be the square root of the distances represented by the latitudeDelta and longitudeDelta returned in the span squared and added. (i.e. Pythagoras theorem, the two side lengths are the horizontal and vertical sides of a triangle and the diagonal is a straight line between your points.)

    Finding latitudeDelta in metres is easy, each degree of latitude is 111km.

    To find meters for the longitudeDelta you need a little bit more code.

    #define EARTH_EQUATORIAL_RADIUS (6378137.0)
    #define WGS84_CONSTANT (0.99664719)
    
    #define degreesToRadians(x) (M_PI * (x) / 180.0)
    
    // accepts decimal degrees. Convert from HMS first if that's what you have
    double lengthOfDegreeLongitude(double degrees) {
    
        double tanDegrees = tanf(degreesToRadians(degrees));
        double beta =  tanDegrees * WGS84_CONSTANT;
        double lengthOfDegree = cos(atan(beta)) * EARTH_EQUATORIAL_RADIUS * M_PI / 180.0;
    
        return lengthOfDegree;
    }
    

    Give that function the longitude of the location you are interested in and multiply the result by the longitudeDelta in degrees to get a distance in meters. Then you have a horizontal distance and a vertical and you can find the diagonal which is what you were looking for.

    Inaccuracy will get bad if you are looking for a distance which is very large in N-S as the length of a degree longitude will be varying over the calculation. And you can refine the 111km for a degree of latitude a bit too, that’s just from memory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the program below, I am trying to calculate the distance between two points.
I'm trying to calculate the distance between two points. The two points I stored
I am trying to calculate the distance between two map point using Google Map
I'm trying to calculate a distance between two sets of coordinate points in an
I am trying to see if the calculated distance between two points is smaller
I am trying to calculate distance between two corelocation objects like this: float meters
In the code below I am trying to calculate the distance between two cities.
I encounter some issues on trying to calculate distance between one location and a
i'm trying to use the GeoKit plugin to calculate the distance between 2 points.
I'm trying to find the distance between two points (for which I've latitudes &

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.