I have an iOS application which parses some data from a JSON feed. One of the bit of downloaded data is a set of coordinates. I am trying to get those coordinates and display them on a MapView in iOS. But I get the following error:
我有一个iOS应用程序,它解析JSON提要中的一些数据。下载的数据之一是一组坐标。我正在尝试获取这些坐标并在iOS的MapView上显示它们。但是我得到了以下错误:
initializing 'cllocationcoordinate2d' with an expression of incompatible type 'id'
初始化'cllocationcoordinate2d'与不兼容类型'id'的表达式
Here is my code:
这是我的代码:
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];
I don't understand what I am doing wrong... Please help.
我不明白我做错了什么……请帮助。
Thanks, Dan.
谢谢你,丹。
2 个解决方案
#1
1
Latitude and longitude do not appear to be of type CLLocationCoordinate2D
, it looks like they are double
s. Try this:
纬度和经度看起来不是CLLocationCoordinate2D类型,看起来它们是双精度的。试试这个:
double lat = [location_lat[choose] doubleValue];
double lon = [location_long[choose] doubleValue];
CLLocationCoordinate2D
represents both latitude and longitude, so you can also do this:
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;
#2
0
Use this macro:
使用这个宏:
CLLocationCoordinate2D cord = CLLocationCoordinate2DMake(x, y);
#1
1
Latitude and longitude do not appear to be of type CLLocationCoordinate2D
, it looks like they are double
s. Try this:
纬度和经度看起来不是CLLocationCoordinate2D类型,看起来它们是双精度的。试试这个:
double lat = [location_lat[choose] doubleValue];
double lon = [location_long[choose] doubleValue];
CLLocationCoordinate2D
represents both latitude and longitude, so you can also do this:
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;
#2
0
Use this macro:
使用这个宏:
CLLocationCoordinate2D cord = CLLocationCoordinate2DMake(x, y);