-6

I want the equation that compute the distance between longitude and latitude of one city and longitude and latitude of another city in c++, oop

  • @aruisdante I know that's why I deleted, probably arc of cyclic sector. – 101010 Jul 30 '14 at 23:38
  • 1
    There are many, many, MANY different way to calculate distance depending on what you want to measure. Are you measuring distance along the ground? Are you measuring a great-arc as the crow flies? Are you measuring straight-line distance from a linear projection like UTM? I would highly suggest some Googling of the various methods for doing this. – aruisdante Jul 30 '14 at 23:39
  • let’s pretend that the cities lie on a flat plane and not on a sphere! – Mero Freestyler Jul 30 '14 at 23:41
  • How are you [projecting](http://en.wikipedia.org/wiki/Map_projection) them onto this flat plain? Once they're there, regular old euclidean distance will give you a reasonable approximation, but for very large distances it's still going to be a rough estimate. – aruisdante Jul 30 '14 at 23:45
  • I need A method that computes the distance from the lon and lat of one city to the lon and lat of another city. Use the standard distance formula to compute this value (let’s pretend that the cities lie on a flat plane and not on a sphere!) – Mero Freestyler Jul 30 '14 at 23:48
  • Stack Overflow is not a homework solving site. You have basically everything you need to solve this problem in the question text, since it's telling you to assume that lat/lon is a linear grid rather than spherical. If you have problems with *specific* parts of your implementation to your solution, we'll happily help you, but we're not going to solve it for you. – aruisdante Jul 30 '14 at 23:50
  • See [How to ask Homework Problems](http://meta.stackexchange.com/questions/10811/how-do-i-ask-and-answer-homework-questions) – aruisdante Jul 30 '14 at 23:53
  • I do not you to solve any thing I just want a math equation because I don't know math to calculate the distance between two cities with lon and lat can you? – Mero Freestyler Jul 30 '14 at 23:54
  • @MeroFreestyler 'I just want a math equation' - why are you asking a maths question on a software site? – Martin James Jul 31 '14 at 00:16
  • because I need a math equation to make an application compute the distance – Mero Freestyler Jul 31 '14 at 00:22

1 Answers1

2

Assuming you're looking for a great arc distance (the most direct route as the bird flies), what you need is the Haversine formula: https://en.wikipedia.org/wiki/Haversine_formula

An example application (which should be trivial to rewrite in any programming language of your choice):

    dlon = lon2 - lon1
    dlat = lat2 - lat1
    a = (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2
    c = 2 * a * tan2(sqrt(a), sqrt(1-a))
    d = R * c //where R is the radius of the Earth