0
代码位于此处。 它基本上可行,但我迷失了方向,无法弄清楚如何从[geocoder]例程返回“point.title”。 point.title是Mapkit注释事物的一部分。我可以像已经注释过的那样,将一个简单的字符串加入到point.title中,但是我无法做到的是返回完整的'locatedAT'或任何placemark.subLocality,例如。项目。我无法从例程中获得位于坐标位置的坐标位置
- (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]; }
请您告诉我您在这里遇到什么错误或问题? –
你想从反向地理编码中获得什么? –
我想把locateAt字符串放到point.title或point.subtitle变量中。它是在地理编码器例程中生成的。 – Postmaster