Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
617 views
in Technique[技术] by (71.8m points)

ios - Sending CLLocationCoordinate2D to parameter of incompatible type my code in Xcode 4.5

I am new to Xcode. I am developing a vehicle tracking app for that I need to display more annotation points simultaneously. For this I need to store the coordinates in the array but it shows the error: Sending CLLocationCoordinate2D to parameter of incompatible type
my code is:

NSString *urlMapString=[NSString stringWithFormat:@"http://logix.com/logix_webservice/mapvehiclelist.php?uid=20&format=json"];
NSURL *urlMap=[NSURL URLWithString:urlMapString];
NSData *dataMap=[NSData dataWithContentsOfURL:urlMap];
if(dataMap!=NULL){
   NSError *errorMap;
   NSMutableArray *coordinates = [[NSMutableArray alloc]init];
   NSDictionary *jsonMap = [NSJSONSerialization JSONObjectWithData:dataMap options:kNilOptions error:&errorMap];
   NSArray *resultsMap = [jsonMap valueForKey:@"posts"];
   for(int count=1;count<resultsMap.count;count++)
      {
       NSDictionary *resMap = [[resultsMap objectAtIndex:count]valueForKey:@"post"];
       NSString *latOrgstring =[resMap valueForKey:@"latitude"];
       latitude=[latOrgstring doubleValue];
       NSString *longitudeString=[resMap valueForKey:@"longitude"];
       longitude=[longitudeString doubleValue];
       //Center
       CLLocationCoordinate2D center;
       center.latitude=latitude;
       center.longitude=longitude;
       [coordinates addObject:center]; //here it shows the error
      }
}

Kindly advice me to solve this problem.
Thank you...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

CLLocationCoordinate2D center isn't an object. You can store only objects in NSArray. Use CLLocation for this.

CLLocation *location = [[CLLocation alloc] initWithLatitude:lat longitude:lon];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...