ビューベースのアプリに次のコードをデプロイしようとしていますが、実行しようとすると次のエラーが発生します。
GPSViewController.h
CLLocationManager *lm;
CLLocation *firstLocation;
CLLocation *secondLocation;
CLLocationDistance *distance;
NSString *distanceString;
GPSViewController.m
firstLocation = [[[CLLocation alloc] initWithLatitude:lat1 longitude:lon1] autorelease];
secondLocation = [[[CLLocation alloc] initWithLatitude:lat2 longitude:lon2] autorelease];
distance = [secondLocation distanceFromLocation:firstLocation]; //CLLocation may not respond to distanceFromLocation
double dist = distance / 1000; //invalid operands to binary
distanceString = [[NSString alloc] stringWithFormat: @"%f", dist];
NSLog(@"the distance between the two points is: %@", distanceString);
上記のコード例で、変数「距離」を「CLLocationDistance」型から「double」型に変換するにはどうすればよいですか?
私は単純に、2 つの異なる CLLocation オブジェクトを使用して 2 点間の距離を計算し、それをコンソールに出力しようとしています。lat1、lon1、lat2、lon2 は double です。
誰が私が間違っているのかを見ることができますか?