5

CLLocationCoordinate2D の緯度と経度の値を数値または文字列値に変換する方法を知りたいと思っていました。Iver はいくつかの方法を試しましたが、うまくいきません:

CLLocationCoordinate2D centerCoord;
centerCoord.latitude = self.locModel.userLocation.coordinate.latitude ;
centerCoord.longitude = self.locModel.userLocation.coordinate.longitude; 
NSString *tmpLat = [[NSString alloc] initWithFormat:@"%g", centerCoord.latitude];
NSString *tmpLong = [[NSString alloc] initWithFormat:@"%g", centerCoord.longitude];

NSLog("User's latitude is: %@", tmpLat);
NSLog("User's longitude is: %@", tmpLong);

これにより、コンパイラによって警告が返されます。

警告は

warning: passing argument 1 of 'NSLog' from incompatible pointer type

どうすればいいですか?

どんな助けでも大歓迎です。

ありがとう

4

1 に答える 1

7

警告が何であるかについては言及していませんが@、おそらく NSLog 文字列の前を忘れたためです。

NSLog(@"User's latitude is: %f", self.locModel.userLocation.coordinate.latitude );
NSLog(@"User's longitude is: %f", self.locModel.userLocation.coordinate.longitude );

更新されたコードは次のようになります。

NSLog(@"User's latitude is: %@", tmpLat);
NSLog(@"User's longitude is: %@", tmpLong);

NSLog は、前に @ 記号が必要な NSString パラメータを想定しています。@ 記号がない場合、文字列は NSString オブジェクトではなくプレーンな C 文字列です。

于 2011-08-01T13:55:41.160 に答える