json - MapKit Annotations Imported From MySQL -


i've been creating app supposed show pins on map stored in mysql database. i've used javascript convert database json converted json data nsstrings, problem here needed convert 2 of these nsstrings doubles because pins need placed via latitude , longitude, here code below when builds shows no issues crashes simulator , shows errors shall post directly under code. if can me solve forever grateful:

hazards.h

#import <foundation/foundation.h> #import <mapkit/mapkit.h>  @interface hazards : nsobject <mkannotation>  @property (nonatomic, assign) cllocationdegrees latitude; @property (nonatomic, assign) cllocationdegrees longitude; @property (nonatomic, copy) nsstring *title; @property (nonatomic, copy) nsstring *subtitle;  @property (nonatomic, strong) nsstring * id; @property (nonatomic, strong) nsstring * route; @property (nonatomic, strong) nsstring * address; @property (nonatomic, strong) nsstring * latitude; @property (nonatomic, strong) nsstring * longitude; @property (nonatomic, strong) nsstring * hazard; @property (nonatomic, strong) nsstring * risk;    // methods - (id) initwithid: (nsstring *) hazardsid androute: (nsstring *) hazardsroute andaddress: (nsstring *) hazardsaddress andlatitude: (nsstring *) hazardslatitude andlongitude: (nsstring *) hazardslongitude andhazard: (nsstring *) hazardshazard andrisk: (nsstring *) hazardsrisk;  @end 

hazards.m

#import "hazards.h"  @implementation hazards @synthesize coordinate, title, subtitle, id, route, address, latitude, longitude, hazard, risk, latitude, longitude;  - (id) initwithid: (nsstring *) hazardsid androute: (nsstring *) hazardsroute andaddress: (nsstring *) hazardsaddress andlatitude: (nsstring *) hazardslatitude andlongitude: (nsstring *) hazardslongitude andhazard: (nsstring *) hazardshazard andrisk: (nsstring *) hazardsrisk {      self = [super init];     if (self)     {         id = hazardsid;         route = hazardsroute;         address = hazardsaddress;         latitude = hazardslatitude;         longitude = hazardslongitude;         hazard = hazardshazard;         risk = hazardsrisk;          latitude = [hazardslatitude doublevalue]; // convert string hazardslatitude double here         longitude = [hazardslongitude doublevalue]; // convert string hazardslongitude double here      } return self; }   -(nsstring *)title {     return self.hazard; }  -(nsstring *)subtitle {     return self.address; }  @end 

viewcontroller.h

#import <uikit/uikit.h> #import <mapkit/mapkit.h> #import "hazards.h"  @interface viewcontroller : uiviewcontroller  @property (nonatomic, strong) nsmutablearray *json; @property (nonatomic, strong) nsmutablearray *hazardsarray;  @property (weak, nonatomic) iboutlet mkmapview *mapview;  #pragma mark - methods -(void) retrievedata;  @end 

viewcontroller.m

#import "viewcontroller.h" #import "hazards.h"  @interface viewcontroller ()  @end  // railway street ballymena coordinates #define ballymena_latitude 54.857719; #define ballymena_longitude -6.280654;  // span #define the_span 0.01f;  #define getdataurl @"www.ryanball.net/royalmail/json.php"  @implementation viewcontroller @synthesize json, hazardsarray, mapview;  - (void)viewdidload {     [super viewdidload];     // create region     mkcoordinateregion myregion;      // center     cllocationcoordinate2d center;     center.latitude = ballymena_latitude;     center.longitude = ballymena_longitude;      //span     mkcoordinatespan span;     span.latitudedelta = the_span;     span.longitudedelta = the_span;      myregion.center = center;     myregion.span = span;      // set our mapview     [mapview setregion:myregion animated: yes];      // annotation     nsmutablearray *locations = [[nsmutablearray alloc] init];     cllocationcoordinate2d location;     hazards *myann;      // pin show royal mail ballymena delivery office     myann = [[hazards alloc] init];     location.latitude = ballymena_latitude;     location.longitude = ballymena_longitude;     myann.coordinate = location;     myann.title = @"royal mail ballymena";     myann.subtitle = @"111, railway street";     [locations addobject:myann];      [self.mapview addannotations:locations];  }  - (void)didreceivememorywarning {     [super didreceivememorywarning];     // dispose of resources can recreated. }  #pragma mark - methods -(void) retrievedata {     nsurl *url = [nsurl urlwithstring:getdataurl];     nsdata *data = [nsdata datawithcontentsofurl:url];      json = [nsjsonserialization jsonobjectwithdata:data options:kniloptions error:nil];      // setup our hazards array     hazardsarray = [[nsmutablearray alloc] init];      (int =0; < json.count; i++) {          // create hazard object         nsstring *hazardsid = [[json objectatindex:i] objectforkey:@"id"];         nsstring *hazardsroute = [[json objectatindex:i] objectforkey:@"route"];         nsstring *hazardsaddress = [[json objectatindex:i] objectforkey:@"address"];         nsstring *hazardslatitude = [[json objectatindex:i] objectforkey:@"latitude"];         nsstring *hazardslongitude = [[json objectatindex:i] objectforkey:@"longitude"];         nsstring *hazardshazard = [[json objectatindex:i] objectforkey:@"hazard"];         nsstring *hazardsrisk = [[json objectatindex:i] objectforkey:@"risk"];          hazards *myhazards = [[hazards alloc] initwithid:hazardsid androute:hazardsroute andaddress:hazardsaddress andlatitude:hazardslatitude andlongitude:hazardslongitude andhazard:hazardshazard andrisk:hazardsrisk];          // add our hazards object our hazards array         [hazardsarray addobject:myhazards];     }      [self.mapview addannotations:hazardsarray]; }  @end 

here error log in console:

2013-04-25 09:04:43.628 royalmailapp[6596:c07] -[hazards setcoordinate:]: unrecognized selector sent instance 0x8c63a60 2013-04-25 09:04:43.629 royalmailapp[6596:c07] * terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[hazards setcoordinate:]: unrecognized selector sent instance 0x8c63a60' * first throw call stack: (0x1b3c012 0x1458e7e 0x1bc74bd 0x146c7ea 0x1b2bcf9 0x1b2b94e 0x2698 0x47e1c7 0x47e232 0x3cd3d5 0x3cd76f 0x3cd905 0x3d6917 0x39a96c 0x39b94b 0x3accb5 0x3adbeb 0x39f698 0x1a97df9 0x1a97ad0 0x1ab1bf5 0x1ab1962 0x1ae2bb6 0x1ae1f44 0x1ae1e1b 0x39b17a 0x39cffc 0x215d 0x2085 0x1) libc++abi.dylib: terminate called throwing exception (lldb)


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -