Skip to content

SteveChiang/SVGeocoder

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SVGeocoder

SVGeocoder is a simple Cocoa wrapper for the Google Geocoding Service. It allows you to quickly geocode and reverse-geocode addresses and coordinates. It is block-based, uses NSURLConnection internally as well as JSONKit (included in package). Make sure you read the Google Geocoding Service Terms of Service before using SVGeocoder.

Installation

  • Drag the SVGeocoder/SVGeocoder folder into your project.
  • Add the CoreLocation, MapKit and AddressBook frameworks to your project.

Usage

Using the Geocoding API

In it’s simplest form, geocoding an address is as simple as:

[SVGeocoder geocode:addressString
         completion:^(NSArray *placemarks, NSError *error) {
             // do something with placemarks, handle errors
         }];

Where placemarks is an array of SVPlacemark objects (see more about that below).

Additionally, you can use Google Geocoding API’s region and bounds parameters to fine-tune your search:

+ (SVGeocoder*)geocode:(NSString *)address bounds:(MKCoordinateRegion)bounds completion:(void (^)(NSArray *placemarks, NSError *error))block;
+ (SVGeocoder*)geocode:(NSString *)address region:(NSString *)region completion:(void (^)(NSArray *placemarks, NSError *error))block;

Using the Reverse Geocoding API

[SVGeocoder reverseGeocode:CLLocationCoordinate2DMake(45.53264, -73.60518)
                completion:^(NSArray *placemarks, NSError *error) {
                    // do something with placemarks, handle errors
                }];

Cancelling requests

Make sure you cancel requests for which the user isn’t waiting on anymore by keeping a pointer to your SVGeocoder object and calling cancel on it. In all cases, the request will time out after 20s.

About the SVPlacemark object

SVPlacemark is basically an MKPlacemark subclass but with a coordinate property. Here’s what an SVPlacemark object looks like:

{
	address = {
		Country = Canada;
		CountryCode = CA;
		State = Quebec;
		Street = "3456 Rue Denis";
		ZIP = "J0K 1S0";
	},
	coordinate = {
		latitude = "46.01529";
		longitude = "-73.76997";
	},
	formattedAddress = "3456 Rue Saint-Denis, Montreal, QC H2L 4S9, Canada"
}

Credits

SVGeocoder is brought to you by Sam Vermette and contributors to the project. If you have feature suggestions or bug reports, feel free to help out by sending pull requests or by creating new issues. If you’re using SVGeocoder in your project, attribution would be nice.

About

A simple geocoder (reverse + forward) for your iOS app.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published