-2

I would like to show my position on the map, I'm using CLLocation for doing it

Here is my code:

CLLocationCoordinate2D coordinate;
coordinate.latitude = latitude;
coordinate.longitude = longitude;

With latitude and longitude is float type and get from database But when i convert to float value so i get wrong value:

float latitude = [myLatString floatValue];

and result:

myLatString : 10.861714

float value : 10.8617144

So i can't load to my mapview with above values.

I searched on google, someone said use NSDecimalNumber but how to work NSDecimalNumber with CLLocation??

Please help me

Community
  • 1
  • 1
  • 1
    What were you expecting to get? And why are you storing numbers as strings in your database instead of just numbers? – Abizern Dec 26 '14 at 11:14

2 Answers2

2

Use of NSDecimalNumber to convert NSString to float.

NSString *myLatString = @"10.8617144";
NSDecimalNumber *decimalPoint = [[NSDecimalNumber alloc] initWithString: myLatString];
float latitude = decimalPoint.floatValue;
Kampai
  • 22,848
  • 21
  • 95
  • 95
  • Really, just a down vote. To the down voter have you read what OP required here. And give a comment if you think that this is wrong answer. – Kampai Dec 26 '14 at 11:47
1

Use doubles. Latitude and longitude are CLLocationDegree, which are double.

Also best to use CLLocationCoordinate2DMake:

CLLocationCoordinate2D loc = CLLocationCoordinate2DMake([myLatString doubleValue], [myLngString doubleValue]);

Ty Kroll
  • 1,385
  • 12
  • 27