发布时间:2022年04月15日 04:38:09分享人:温暖手心的少年来源:互联网13
通过经纬度定位城市:CLGeocoder * geoCoder =[[[CLGeocoder alloc] init] autorelease];
[geoCoderreverseGeocodeLocation:newLocationcompletionHandler:^(NSArray *placemarks, NSError*error) {
for(CLPlacemark * placemark in placemarks) {
NSString *myCity =placemark.locality;
if ([myCity isEqualToString:@"长安"]) {
myCity =@"西安";
}
self.myLabel.text = [NSString stringWithFormat:@"(%@,%@)||%@%@",currentLatitude,currentLongitude,placemark.country,myCity];
if (self.myLabel.text.length > 0) {
[self.locationManager stopUpdatingLocation];
}
}
}];
通过城市名定位经纬度:
CLGeocoder———— * geocoder = [[CLGeocoder alloc] init]; |
066 |
[geocodergeocodeAddressString:_searchTextField.textcompletionHandler:^(NSArray *placemarks, NSError *error){ |
071 |
NSLog(@ "Geocodererror : %@" ,error); |
075 |
if ([placemarkscount] == 0) |
077 |
NSLog(@ "Couldfound the address." ); |
081 |
CLPlacemark* placeMark = [placemarks objectAtIndex:0]; |
083 |
_mapView.centerCoordinate= placeMark.location.coordinate; |
085 |
mAnnotationView* annotationView = [[mAnnotationView alloc]initWithCLLocationCoordinate2d:placeMark.location.coordinatetitle:placeMark.locality subTitle:[NSStringstringWithFormat:@ "%@-%@" ,placeMark.country,placeMark.administrativeArea]]; |
087 |
[_mapViewaddAnnotation:annotationView]; |
089 |
[_mapViewselectAnnotation:annotationView animated:YES]; |
092 |
NSLog(@ "country:%@,locality:%@,%@,%@" ,placeMark.country,placeMark.locality,placeMark.administrativeArea,placeMark.region); |
094 |
[indicatorViewstopAnimating]; |
爱华网本文地址 » http://www.413yy.cn/a/25101015/261204.html