Skip to content
aferre edited this page Oct 9, 2011 · 13 revisions

cf Google Geocoding API page for the behaviour of the WS.

Install

Just copy afGMapsGeocodingRequest and afGoogleMapsAPIRequest files to your project (you need both ASIHTTP and JSON frameworks for the wrapper to work).

How to use

Create a request to geocode an address:

afGMapsGeocodingRequest *req = [afGMapsGeocodingRequest request];
req.afDelegate = self;
[req setLatitude:lat andLongitude:lng];

[req startAsynchronous];

Or to reverse geocode coordinates:

afGMapsGeocodingRequest *req = [afGMapsGeocodingRequest request];
req.afDelegate = self;
[req setTheAddress:@""];

[req startAsynchronous];

You can use bounds in the request (see Google documentation).

[req setBoundsUpperLeft:CGPointMake(x1,y1) downRight:CGPointMake(x2,y2)

Then, simply make your class inherit the afGoogleMapsGeocodingDelegate protocol, and implement the following delegate functions (all optional):

-(void) afGeocodingWSStarted:(afGMapsGeocodingRequest *)ws;

-(void) afGeocodingWSFailed:(afGMapsGeocodingRequest *)ws withError:(NSError *)er;

Use those if requesting coordinates from address. If multiple coordinates are returned, the second delegate function will be called. If not, the first one will be called.

-(void) afGeocodingWS:(afGMapsGeocodingRequest *)ws gotCoordinates:(CLLocationCoordinate2D) coordinates fromAddress:(NSString *)address;

-(void) afGeocodingWS:(afGMapsGeocodingRequest *)ws gotMultipleCoordinates:(NSArray *)coordinates fromAddress:(NSString *)address;

Use those if requesting address from coordinates. If multiple addresses are returned, the second delegate function will be called. If not, the first one will be called.

-(void) afGeocodingWS:(afGMapsGeocodingRequest *)ws gotAddress:(NSString *)address fromLatitude:(double)latitude andLongitude:(double)longitude;

-(void) afGeocodingWS:(afGMapsGeocodingRequest *)ws gotMultipleAddresses:(NSArray *)addresses fromLatitude:(double)latitude andLongitude:(double)longitude;
Clone this wiki locally