■2つの地点の距離の計算
//現在地情報取得
- (void) locationManager: (CLLocationManager *) manager
didUpdateToLocation: (CLLocation *) newLocation
fromLocation: (CLLocation *) oldLocation{
[manager stopUpdatingLocation];
user_lat=newLocation.coordinate.latitude;
user_lng=newLocation.coordinate.longitude;
CLLocation *pos;
CLLocationDistance dis;
CLLocation *nowLocation = [[CLLocation alloc] initWithLatitude:user_lat
longitude:user_lng];
cellData=[[NSMutableArray alloc]init];
for(NSDictionary *data in listData){
double lat=[[data objectForKey:@"store_lat"]doubleValue]; //店舗の経度・緯度
double lng=[[data objectForKey:@"store_lng"]doubleValue];
pos = [[CLLocation alloc] initWithLatitude:lat
longitude:lng];
//現在地点から店舗の距離を返す
dis = [nowLocation distanceFromLocation:pos];
//10km圏内のものをリストに追加
if(dis < 10000){
[cellData addObject:[data objectForKey:@"store_name"]];
}
}
}
- (void) locationManager: (CLLocationManager *) manager
didFailWithError: (NSError *) error {
if([error code] == kCLErrorDenied) {
// 設定で位置情報がoffになっている場合
if (![CLLocationManager locationServicesEnabled]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"GPS Error"
message:@"位置情報設定をOnにしてください"
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
// 位置情報の取得を「許可しない」を選択した場合
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"GPS Error"
message:@"位置情報の利用を許可してください"
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
}
}
てな感じでできました。
またまた、navigationControllerにて一個前の画面に戻りたいときの実装もできたので、書き書き。
//現在の画面の位置
NSUInteger index = [self.navigationController.viewControllers indexOfObject:self];
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:index-1] animated:YES];
現在地から-1した所に戻るとな。
めでたしめでたし。