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