That is, the relevant geographic coordinates are obtained based on a nsstring literal description object.
Using the Clgeocoder class operation, the specific method:
1>geocodeaddressdictionary:completionhandler: Querying by specifying an address information Dictionary object parameter
2>geocodeaddressstring:completionhandler: Querying by specifying an address information string parameter
3>geocodeaddressstring:inregion:completionhandler: Querying by making address information strings and query scopes
-(Ibaction) Geocodequery: (ID) sender{NSString*querystr =Nil; //Enter an address string from the interface text box if(_textfield.text = = Nil | | [_textfield.text length] = =0) { return ; } Clgeocoder*geocoder =[[Clgeocoder alloc] init]; [Geocoder geocodeaddressstring:querystr Completionhandler:^ (Nsarray *placemarks, Nserror *error) {NSLog (@"Query record number:%i", [placemarks Count]); if([Placemarks Count] >0) {Clplacemark*placemark = [Placemarks objectatindex:0]; cllocationcoordinate2d coordinate=placemark.location.coordinate; //generate latitude and longitude stringsNSString *strcoordinate = [NSString stringWithFormat:@"Longitude:%3.5f, Latitude:%3.5f", Coordinate.latitude,coordinate.longitude]; Nsdictionary*addressdict =placemark.addressdictionary; NSString*address = [addressdict objectforkey: (NSString *) Kabpersonaddressstreetkey]; Address= Address = = Nil?@"": Address; NSString*state = [addressdict objectforkey: (NSString *) Kabpersonaddressstatekey]; State= state = = Nil?@"": State; NSString*city = [addressdict objectforkey: (NSString *) Kabpersonaddresscitykey]; City= City = = Nil?@"": City; //gets a landmark corresponding to a readable text message that is typically returned to the UI displayNSString *streetinfo = [NSString stringWithFormat:@"%@\n%@\n%@\n%@\n", strcoordinate,state,address,city]; } }];}
Use GeocodeAddressString:inRegion:completionHandler: Specify the query area:
Clregion *region = [[Clregion alloc] initcircularregionwithcenter:_currlocation.coordinate radius:1000.0f Identifier:@ "geocoderegion"]; *geocoder = [[Clgeocoder alloc] init]; [Geocoder geocodeaddressstring:querystr inregion:region Completionhandler:^ (Nsarray *placemarks, NSError * Error) { ... }];
The Clregion object encapsulates a geographic region class.
Constructor method Parameters:
Center: Specify a regional center point
Radius: Specify the radius of the area in meters
Identifier: Specify an identity for the zone