2

いくつかの場所を設定し、それらの場所のいずれかによるものかどうかをアプリに確認させたいのですが、ユーザーがその場合は、現在の場所にUIPickerView基づいて設定した値を自動選択します。

私はiOSのObjectiveCとコーディングにかなり精通していますが、コアロケーションについては何もしていません。私は何かを読みましたが、助けが欲しいです。

私が持っているのは、plistファイル内の場所の緯度と経度です。現在のユーザーの場所を取得し、このコードで座標を取得できます

  int degrees = newLocation.coordinate.latitude;
  double decimal = fabs(newLocation.coordinate.latitude - degrees);
  int minutes = decimal * 60;
  double seconds = decimal * 3600 - minutes * 60;
  NSString *lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"", 
                   degrees, minutes, seconds];

  degrees = newLocation.coordinate.longitude;
  decimal = fabs(newLocation.coordinate.longitude - degrees);
  minutes = decimal * 60;
  seconds = decimal * 3600 - minutes * 60;
  NSString *longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"", 
                     degrees, minutes, seconds];

私がやりたいのは、ユーザーの現在の場所をplistファイルの場所と比較することです。ユーザーが、plistファイルのいずれかの場所から数マイル以内にある場合は、UIPickerViewのバルブが自動的に選択されます。UIPickerViewから何かを選択する方法はすでに知っています。

4

2 に答える 2

1

distanceFromLocation:インスタンスメソッド(CLLocationオブジェクトにあります)を使用できます

CLLocation *myLocation = 'get the location'
CLLocation *storedLocation = 'get the stored location'
CLLocationDistance distance = [myLocation distanceFromLocation:storedLocation];

CLLocationDistanceは。に置き換えることもできますdouble。これは、iOSデベロッパーライブラリの概要です。

于 2012-06-19T13:52:09.687 に答える
0

私はそれを理解しました私はちょうどこのような配列をループしました

    NSArray *locations = [_locationDict allKeys];
NSInteger count = [location count];
for (int i = 0; i < count; i++){

    NSString *locationName = [[NSString alloc] initWithFormat:@"%@",[locations objectAtIndex:i]];


NSDictionary *dict = [_locationDict objectForKey:locationName];
CLLocation *itemLocation = [[CLLocation alloc] initWithLatitude:[[dict objectForKey:@"latitude"] floatValue] longitude:[[dict objectForKey:@"longitude"] floatValue]];

CLLocationDistance distance = [itemLocation distanceFromLocation:newLocation];
    NSLog(@"%F",distance);

    if (distance < 100) {
        whatby.text = [locations objectAtIndex:i];
    }
        }
于 2012-06-25T17:27:23.663 に答える