将NSString转换为double

时间:2013-04-24 20:38:58

标签: nsstring double

我已经使用JSON将一个mysql数据库导入NSStrings,但现在我需要将其中两个转换为双精度来表示纬度和经度,但我不确定如何完成我的代码。

Hazards.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

Hazards.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

0 个答案:

没有答案