MrZoidberg / SVGeocoder

Simple Cocoa wrapper for the Google Geocoding Service

Home Page:http://samvermette.com/164

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Important note if your project doesn’t use ARC: you must add the -fobjc-arc compiler flag to SVGeocoder.m and SVPlacemark.m in Target Settings > Build Phases > Compile Sources.

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 blocked-based, uses NSURLConnection, ARC, as well as NSJSONSerialization to automatically parse JSON responses (making it only compatible with iOS 5+). 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 frameworks to your project.

Usage

Using the Geocoding API

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

[SVGeocoder geocode:addressField.text
         completion:^(NSArray *placemarks, NSHTTPURLResponse *urlResponse, 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 parameter to fine-tune your search:

+ (SVGeocoder*)geocode:(NSString *)address bounds:(MKCoordinateRegion)bounds completion:(SVGeocoderCompletionHandler)block;
+ (SVGeocoder*)geocode:(NSString *)address region:(CLRegion *)region completion:(SVGeocoderCompletionHandler)block;

Using the Reverse Geocoding API

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

About the SVPlacemark object

SVPlacemark is now a simple NSObject. Here’s a sample placemark returned for string “3456 Saint-Denis, Montreal”:

{
    ISOcountryCode = CA;
    administrativeArea = Quebec;
    coordinate = "45.517363, -73.568376";
    country = Canada;
    formattedAddress = "3456 Rue Saint-Denis, Montreal, QC H2X 3L1, Canada";
    locality = Montreal;
    postalCode = "H2X 3L1";
    subAdministrativeArea = "Communaut\U00e9-Urbaine-de-Montr\U00e9al";
    subLocality = "Le Plateau-Mont-Royal";
    subThoroughfare = 3456;
    thoroughfare = "Rue Saint-Denis";
}

There’s also a region (MKCoordinateRegion) property in case the returned placemark isn’t a pinned location, and a location (CLLocation) convenience property.

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

Simple Cocoa wrapper for the Google Geocoding Service

http://samvermette.com/164

License:Other


Languages

Language:Objective-C 98.0%Language:Ruby 2.0%