JSON を使用して mysql データベースを NSStrings にインポートしましたが、緯度と経度を表すためにこれらのうちの 2 つを double に変換する必要がありますが、コードを完成させる方法がわかりません。
ハザード.h
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface Hazards : NSObject <MKAnnotation>
// @property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@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
ハザード.m
#import "Hazards.h"
@implementation Hazards
@synthesize coordinate, title, subtitle, ID, ROUTE, ADDRESS, LATITUDE, LONGITUDE, HAZARD, RISK;
- (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 = ; // convert the string hazardsLatitude to a double here
longitude = ; // convert the string hazardsLongitude to a double here
}
return self;
}
/*-(CLLocationCoordinate2D)coordinate
{
return CLLocationCoordinate2DMake(self.LATITUDE, self.LONGITUDE);
}*/
-(NSString *)title
{
return self.HAZARD;
}
-(NSString *)subtitle
{
return self.ADDRESS;
}
@end