0
コードはこちらです。 これは基本的には機能しますが、私は道を紛失してしまい、[geocoder]ルーチンから "point.title"を戻す方法を理解することができません。 point.titleはMapkitアノテーションの一部です。私はコメントアウトされているので、単純な文字列をpoint.titleに入れることができますが、私がそれを行うことができないのは、完全な 'locatedAT'または実際にplacemark.subLocalityのどれかを返すことです。アイテム。locateAtジオコードを取得できません。座標の位置はルーチンから返されます
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 800, 800);
[self.mapView setRegion:[self.mapView regionThatFits:region] animated:YES];
// Add an annotation
MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
point.coordinate = userLocation.coordinate;
//point.title = @"Where am I?";
//point.subtitle = @"I'm here!!!";
////////////////////////
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
CLLocation *loc = [[CLLocation alloc]initWithLatitude:userLocation.coordinate.latitude longitude:userLocation.coordinate.longitude];
[geocoder reverseGeocodeLocation: loc
completionHandler:^(NSArray* placemarks, NSError* error){
CLPlacemark *placemark = [placemarks objectAtIndex:0];
if (placemark) {
// NSLog(@"placemark %@",placemark);
//String to hold address
NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];
// NSLog(@"addressDictionary %@", placemark.addressDictionary);
// NSLog(@"placemark %@",placemark.region);
// NSLog(@"placemark %@",placemark.country); // Give Country Name
// NSLog(@"placemark %@",placemark.locality); // Extract the city name
// NSLog(@"location %@",placemark.name);
// NSLog(@"location %@",placemark.ocean);
// NSLog(@"location %@",placemark.postalCode);
// NSLog(@"location %@",placemark.subLocality);
//Print the location to console
// NSLog(@"I am currently at %@",locatedAt);
point.title = locatedAt;
}
else {
NSLog(@"Could not locate");
}
}
];
///////////////////////////
NSLog(@"point.title %@",point.title);
[self.mapView addAnnotation:point];
[self.mapView selectAnnotation:point animated:YES]; }
ここにはどのようなエラーや問題があるのですか教えてください。 –
逆ジオコーディングから何を得たいですか? –
私は、locatedAt文字列をpoint.titleまたはpoint.subtitle変数に入れようとしています。ジオコーダー・ルーチンで生成されます。 – Postmaster