-1

I need to know how to calculate some sort of perimeter around a lat/long coordinate (in a floating point number) in an "if" statement that looks somewhat like this:

if (lat != perimeterLat && long != perimeterLong) {
    // alert
}

If there is a better way of doing this (instead of using an "if" statement) please let me know.

Thanks, Jacob Cross

UPDATE:

Ok. So I figured it out. What I am going to do is this:

- (void)locationChange:(CLLocation *)newLocation:(CLLocation *)oldLocation { 
    CLLocationCoordinate2D newCoordinate = [newLocation coordinate];
    CLLocationCoordinate2D oldCoordinate = [oldLocation coordinate];

    CLLocationDistance meters = [newCoordinate distanceFromLocation:oldLocation];
}

And that is going to be how I figure out the distance away.

Found Answer Here

Thanks for everyone's help!

Community
  • 1
  • 1
RMK-Jacob
  • 209
  • 1
  • 4
  • 15

2 Answers2

0

On a sphere you can use the haversine formula to calculate the great circle distance between two points.

High Performance Mark
  • 77,191
  • 7
  • 105
  • 161
Micromega
  • 12,486
  • 7
  • 35
  • 72
  • How would I do that? I have never heard of the Harvesine formula before. Also is it possible to do that with lat/long? – RMK-Jacob Jul 15 '12 at 22:15
  • @Zéychin Can I do that with Lat/Long? And I am doing this is Objective-C (Xcode). – RMK-Jacob Jul 15 '12 at 22:19
  • Look just under "where h is haversin(d/r), or more explicitly:" and there are explicit formulas in terms of more familiar trigonometric functions. Phi1 and Phi2 are the latitudes of respective points and Psi1 and Psi2 are your longitudes of respective points. – Zéychin Jul 15 '12 at 22:22
  • I'm not good at math just copy and paste but the law of harvesine is the same like the law of triangle inequality for planes. It's means it applicable to distance functions only. There are other metrics like kg, newton and so on. Is that what you wanted to know? – Micromega Jul 15 '12 at 22:24
0

Ok. So I figured it out. What I am going to do is this:

- (void)locationChange:(CLLocation *)newLocation:(CLLocation *)oldLocation { 
    CLLocationCoordinate2D newCoordinate = [newLocation coordinate];
    CLLocationCoordinate2D oldCoordinate = [oldLocation coordinate];

    CLLocationDistance meters = [newCoordinate distanceFromLocation:oldCoordinate];
}

And that is going to be how I figure out the distance away.

Found Answer Here

Thanks for everyone's help!

Jacob

Community
  • 1
  • 1
RMK-Jacob
  • 209
  • 1
  • 4
  • 15