Giter VIP home page Giter VIP logo

svgeocoder's Introduction

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.

What’s different here

This implementation let you set the region optional parameter of the Google Geocoding API.

This implementaton uses GMSCoordinateBounds instead of MKCoordinateRegion thus allowing you to throw Apple’s MapKit away.
Note, that it uses rather rough approximation of CLRegion (conversion coordinate+radius to four coordinates).
As far as original SVGeocoder is iOS 5.0+ compatible, Google Maps SDK for iOS (1.2.0 for the moment) is 5.1+ compatible.

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, Google Maps SDK for iOS (1.2.0+) 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 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 (GMSCoordinateBounds) property in case the returned placemark isn’t a pinned location, and a location (CLLocation) convenience property.

Credits

Orginal 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.

svgeocoder's People

Contributors

samvermette avatar echoz avatar maniak-dobrii avatar lucatorella avatar xissburg avatar corduroy avatar aufflick avatar cricketgeek avatar

Watchers

James Cloos avatar  avatar

Forkers

lucatorella

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.