문제

I'm currently working on an app that works with locations and therefore I have the following code:

CLLocationCoordinate2d coord;
coord.longitude = [longitude doubleValue];
coord.latitide = [latitude doubleValue];

Seems legit, doesn't it? Now longitude and latitude are STRINGS like "10.112233". I know that normally double hasn't got points in there, but the cllocationcoordinate2d wants it like that...

Now, if you NSLog the strings, they work just fine, but if you NSLog the doubleValues it simply return nothing. How can I fix that?

도움이 되었습니까?

해결책

The following should work:

NSString *coordinateAsString = @"10.112233";
coord.longitude = [[NSDecimalNumber decimalNumberWithString:coordinateAsString] doubleValue];

다른 팁

Can you try using NSDecimalNumber like following:

NSString *string = @"10.112233";
NSDecimalNumber *number = [NSDecimalNumber decimalNumberWithString:string];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top