Nav Link On

iPhone Dev Forums > General Development > SDK Coding Help > CLLocationCoordinate2D not giving the position I expect on MKMapView

Reply

 

LinkBack Thread Tools Display Modes
Old 04-27-2010, 11:49 AM   #1 (permalink)
Junior Member
Default Avatar
 
Join Date: Apr 2010
Posts: 8
Default CLLocationCoordinate2D not giving the position I expect on MKMapView

Hi everybody,

I am using a MapView to display the position of a property. These coordinates will eventually be pulled from a database, so I'm not using CoreLocation to return a coordinate in this part of the app.

Here is my code:
Code:

You must Login or Register to view and contribute code! This is done to increase participation in helping one another out, if you have been helped please pass on the favor.

	CLLocationCoordinate2D coord;
	coord.longitude = (CLLocationDegrees)[rp.locLat doubleValue];
	coord.latitude = (CLLocationDegrees)[rp.locLng doubleValue];
	
	UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Title" message:[[NSString alloc]initWithFormat:@"%f, %f", [rp.locLat doubleValue], [rp.locLng doubleValue]] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
	[alert show];
	[alert release];
	
	MKCoordinateRegion region;
    region.center = coord;
    MKCoordinateSpan span = {1, 1};
    region.span = span;
    mapView.region = region;
Just so you are aware, rp.locLat and rp.locLng are both of type NSString and hardcoded to 53.478239, -2.246704 respectively. If you enter this in maps.google.com it will display a pointer in Manchester, UK. This is correct.

However, the MapView centres the map just off the coast of the Seychelles which is obviously not correct. Initially I thought maybe it doesn't want a decimal representation of the lat/lng so I got the CoreLocation functionality to spit out a lat/lng for the devices current position.

The UIAlertView above displays the text: "53.478239, -2.246704", so I know that the values stored in the rp object are correct.

This gives me 37.332..., -122.031... (Apples HQ, which is correct). You can enter these values into maps.google.com and it gives you the correct position so I can assume my values are in the correct format.

The only thing I can think of is these lines:
Code:

You must Login or Register to view and contribute code! This is done to increase participation in helping one another out, if you have been helped please pass on the favor.

	coord.longitude = (CLLocationDegrees)[rp.locLat doubleValue];
	coord.latitude = (CLLocationDegrees)[rp.locLng doubleValue];
are somehow corrupting the values passed to the coord object. I've no clue why though, so any ideas would be most welcome - especially since I am using the same values in the UIAlertView which are displaying exactly how i'd expect...

I'm stumped, so if anyone has any ideas at all that would be great.

Cheers,
Dave
cavedox is offline   Reply With Quote
Old 04-27-2010, 11:53 AM   #2 (permalink)
Junior Member
Default Avatar
 
Join Date: Apr 2010
Posts: 8
Default

Oh my god, never mind I'm a FOOL.

I was assigning the longitude to the latitude property, and the latitude to the longitude property.

Mods feel free to delete this utterly pointless thread I started. My apologies.

Dave
cavedox is offline   Reply With Quote
Old 08-17-2013, 11:50 PM   #3 (permalink)
Junior Member
Default Avatar
 
Join Date: Aug 2013
Posts: 16
Default

This post is*very*informative.*Thank you!
__________________
www.myannualcreditreport.com
Pasternak is offline   Reply With Quote
Reply

iPhone Dev Forums > General Development > SDK Coding Help


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0 RC1