[英]How to store co-ordinates - iOS
我有一個iOS應用程序,可以解析JSON feed中的一些數據。 已下載數據中的一個是一組坐標。 我正在嘗試獲取這些坐標並將其顯示在iOS中的MapView上。 但是我收到以下錯誤:
使用不兼容類型'id'的表達式初始化'cllocationcoordinate2d'
這是我的代碼:
int choose = 4;
NSArray *location_lat = [[[res objectForKey:@"data"] valueForKey:@"location"] valueForKey:@"latitude"];
NSArray *location_long = [[[res objectForKey:@"data"] valueForKey:@"location"] valueForKey:@"longitude"];
NSLog(@"\n\nLat:%f Lon:%f", [location_lat[choose] doubleValue], [location_long[choose] doubleValue]);
CLLocationCoordinate2D lat = [location_lat[choose] doubleValue];
CLLocationCoordinate2D lon = [location_long[choose] doubleValue];
MKCoordinateRegion region = { {0.0, 0.0}, {0.0, 0.0} };
region.center.latitude = lat;
region.center.longitude = lon;
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[map setRegion:region animated: YES];
ContentView *ann = [[ContentView alloc] init];
ann.title = @"Current Location";
ann.subtitle = @"";
ann.coordinate = region.center;
[map addAnnotation:ann];
我不明白自己在做什么錯...請幫助。
謝謝,丹。
緯度和經度似乎不是CLLocationCoordinate2D
類型,看起來好像是double
。 嘗試這個:
double lat = [location_lat[choose] doubleValue];
double lon = [location_long[choose] doubleValue];
CLLocationCoordinate2D
代表緯度和經度,因此您也可以這樣做:
CLLocationCoordinate2D center = CLLocationCoordinate2DMake([location_lat[choose] doubleValue], location_long[choose] doubleValue]);
MKCoordinateRegion region = { {0.0, 0.0}, {0.0, 0.0} };
region.center = center;
使用此宏:
CLLocationCoordinate2D cord = CLLocationCoordinate2DMake(x, y);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.