Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

xArtx

macrumors 6502a
Original poster
Mar 30, 2012
764
1
Hi Guys,
Pretty much what the title says.
I can read from a CLLocation into a float value:
Code:
latitude = positionone.coordinate.latitude;
but the compiler doesn't want to know about writing back
to an object I declared myself:
Code:
positionone.coordinate.latitude = latitude;
I found that odd. Is there another way to do it?
Cheers, Art.
 
CLLocation is an NSObject. CLLocationCoordinate2D is a struct. So this really represents why Apple choosing dot (.) for it's syntactic sugar was a bad idea as what is really being called here is:

Code:
[positionone setCoordinate.latitude:latitude];

as the first dot gets expanded/replaced with the accessor. It shoudl be clear that the above is absolute nonsense hence the compiler complaining. This should work:

Code:
CLLocationCoordinate2D coord = positionone.coordinate;
coord.latitude=latitude;
positionone.coordinate = coord;
 
CLLocation is an NSObject. CLLocationCoordinate2D is a struct. So this really represents why Apple choosing dot (.) for it's syntactic sugar was a bad idea as what is really being called here is:

Code:
[positionone setCoordinate.latitude:latitude];

as the first dot gets expanded/replaced with the accessor. It shoudl be clear that the above is absolute nonsense hence the compiler complaining. This should work:

Code:
CLLocationCoordinate2D coord = positionone.coordinate;
coord.latitude=latitude;
positionone.coordinate = coord;

Thanks, Apple can have their two plus signs back, I really just want them
to calculate all my distances between arbitrary coordinates for me :)

Bah!
It won't allow the third line. This time it knows it's a read only property.
It might mean the harder way.... haven't implemented the great circle formula before, but i doesn't look too difficult.
 
Last edited:
Have you looked into CLLocation's distanceFromLocation: instance method?

That's what I wanted to use, but you have to be able to write coordinates to
a CLLocation object first (in order to calc the distance between arbitrary points).
It's a cinch if you are using it between points the device has actually been to.

Didn't take long to find a drop in solution (in Km)
Code:
    //calculate haversine distance for linear distance Km
    double lat1 = screenbrlat;
    double long1 = screentllon;
    double lat2 = screenbrlat;
    double long2 = screenbrlon;
    double dlong = (long2 - long1) * d2r;
    double dlat = (lat2 - lat1) * d2r;
    double a = pow(sin(dlat/2.0), 2) + cos(lat1*d2r) * cos(lat2*d2r) * pow(sin(dlong/2.0), 2);
    double c = 2 * atan2(sqrt(a), sqrt(1-a));
    double d = 6367 * c;
    float distance = d;

Edit,,, In this case, instead of drawing the usual ruler to a GPS screen,
I want to always display the total width of the screen in Kilometers.
The program already knows the real geographic coordinates of each corner of the screen.
 
Last edited:
Here's a quick version using CLLocation:
Code:
CLLocation *oldLocation = [[CLLocation alloc] initWithLatitude:lat1 longitude:long1];
CLLocation *newLocation = [[CLLocation alloc] initWithLatitude:lat2 longitude:long2];;
CLLocationDistance meters = [newLocation distanceFromLocation:oldLocation];
 
Lol.. Bummer :D ...I might as well check for consistency!

I just learned that the ruler at the bottom of the screen is rather useless
if the view shows a whole continent.
As long as the grid is square, the distance measured across the screen
at one point on the y axis is not going to be the same on another.
 
Sorry, internet is almost back to dial up for exceeding bandwidth.
Anyway,

AVEC-1_zpsb0d95d45.png


I might as well check for consistency!
I totally got that answer wrong...
I might as well check that the output of the C routine posted above
matches the output of the native code you posted.
 
Last edited:
Measure the distance of one degree on a grid.
We can get a mean radius from a mean circumference which is defined in the formula.

----------

The formula doesnt account for the Earth's slight eliptiod (I don't think). Now I'm no longer thinking
I can just measure a degree longitude at 45deg South, and multiply it to see if the mean circumference matches.

----------

The formula doesnt account for the Earth's slight eliptiod (I don't think) But the defined mean circumference might. Now I'm no longer thinking
I can just measure a degree longitude at 45deg South, and multiply it to see if the mean circumference matches.
 
Hey, I followed through :)

Not sure I explained myself well there.
In a nutshell, measure what each formula thinks the circumference of
the Earth is at a given degree of latitude, and compare with a known one
(doing it by measuring one grid and multiplying it).

I think I'd rather just keep the C one because I can access every component of it.
If I move to Mars for example, there's only one small change to make,
and don't have to wait for an iOS update.

They do disagree slightly, but I do think that's due to a different definition
of mean circumference of the Earth.
If you wanted to be anal, you could increment it in the C version
to see if it ever agreed all of the time.

Measurement across the screen for the picture posted above,
Australia must be in a different lat postion on the screen,
this time it's 4320.7Km across the middle versus the native code 4333.9Km.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.