1

私はこれで考えられるあらゆる方法を試しましたが、うまくいきませんでした。

次のようなエントリを持つ XML ファイルがあります...

<lat>53.358242</lat>
<lon>-6.227800</lon>

ファイルは NSXMLParser で解析され、他のものを取得しますが、これらを注釈にフィードしてピンをドロップすることはできません。.h ファイルには次のものがあります。

@interface LocationList : NSObject
@property (nonatomic, strong) NSString *loc_name;
@property (nonatomic, strong) NSString *lat;
@property (nonatomic, strong) NSString *lon;

次に、NSStringを座標に変換しようとします..

CLLocationCoordinate2D pinCoordinate;
pinCoordinate.latitude = [theLocationList.lat doubleValue]; 
pinCoordinate.longitude = [theLocationList.lon doubleValue]; 

しかし、私は0で終わります。

これを試してみましたが、負の値を処理できませんでした。

NSString *digits = [theLocationList.lon stringByTrimmingCharactersInSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]];
NSLog(@"Attempts: %f", [digits floatValue]);

私に掘り下げてくれる人はいますか?

4

1 に答える 1

1

ソリューションをわずかに変更するだけでうまくいくはずです-次のように に置き換えますdecimalDigitCharacterSetcharacterSetWithCharactersInString:@"+-0123456789."

NSString *digits = [theLocationList.lon stringByTrimmingCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:@"+-0123456789."] invertedSet]];
NSLog(@"Attempts: %f", [digits floatValue]);
于 2012-06-27T15:01:12.457 に答える