通过经纬度定位城市:
CLGeocoder * geoCoder = [[[CLGeocoder alloc] init] autorelease];
通过城市名定位经纬度:
CLGeocoder * geocoder = [[CLGeocoder alloc] init]; |
065 | |
066 | [geocoder geocodeAddressString:_searchTextField.text completionHandler:^(NSArray *placemarks, NSError *error) { |
067 | |
068 | |
069 | if (error) |
070 | { |
071 | NSLog(@ "Geocoder error : %@" ,error); |
072 | return ; |
073 | } |
074 | |
075 | if ([placemarks count] == 0) |
076 | { |
077 | NSLog(@ "Could found the address." ); |
078 | return ; |
079 | } |
080 | |
081 | CLPlacemark * placeMark = [placemarks objectAtIndex:0]; |
082 | |
083 | _mapView.centerCoordinate = placeMark.location.coordinate; |
084 | |
085 | mAnnotationView * annotationView = [[mAnnotationView alloc] initWithCLLocationCoordi "%@-%@" ,placeMark.country,placeMark.administrativeArea]]; |
086 | |
087 | [_mapView addAnnotation:annotationView]; |
088 | |
089 | [_mapView selectAnnotation:annotationView animated:YES]; |
090 | |
091 | |
092 | NSLog(@ "country:%@,locality:%@,%@,%@" ,placeMark.country,placeMark.locality,placeMark.administrativeArea,placeMark.region); |
093 | |
094 | [indicatorView stopAnimating]; |
095 | |
096 | }]; |