Coder Social home page Coder Social logo

lminhtm / lmgeocoder Goto Github PK

View Code? Open in Web Editor NEW
139.0 9.0 38.0 4.1 MB

Simple wrapper for geocoding and reverse geocoding, using both Google Geocoding API and Apple iOS Geocoding Framework.

License: MIT License

Objective-C 97.16% Ruby 2.84%
ios objective-c geocoder reverse-geocode geocode geocoding reverse-geocoding swift

lmgeocoder's Introduction

LMGeocoder

LMGeocoder is a simple wrapper for geocoding and reverse geocoding, using both Google Geocoding API and Apple iOS Geocoding Framework.

CI Status Version License Platform

Features

  • Wrapper for Geocoding and Reverse geocoding with blocked-based coding.
  • Use both Google Geocoding API and Apple iOS Geocoding Framework.

Requirements

iOS 8.0 or higher

Installation

LMGeocoder is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'LMGeocoder'

Swift Version

https://github.com/lminhtm/LMGeocoderSwift

Usage

Geocoding

[[LMGeocoder sharedInstance] geocodeAddressString:addressString
                                          service:LMGeocoderServiceGoogle
                               alternativeService:LMGeocoderServiceApple
                                completionHandler:^(NSArray *results, NSError *error) {
                                    if (results.count && !error) {
                                        LMAddress *address = [results firstObject];
                                        NSLog(@"Coordinate: (%f, %f)", address.coordinate.latitude, address.coordinate.longitude);
                                    }
                                }];

Reverse Geocoding

[[LMGeocoder sharedInstance] reverseGeocodeCoordinate:coordinate
                                              service:LMGeocoderServiceGoogle
                                   alternativeService:LMGeocoderServiceApple
                                    completionHandler:^(NSArray *results, NSError *error) {
                                        if (results.count && !error) {
                                            LMAddress *address = [results firstObject];
                                            NSLog(@"Address: %@", address.formattedAddress);
                                        }
                                    }];

Cancel Geocode

[[LMGeocoder sharedInstance] cancelGeocode];

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

License

LMGeocoder is available under the MIT license. See the LICENSE file for more info.

Author

Minh Nguyen

lmgeocoder's People

Contributors

dpyro avatar fawkeswei avatar lminh avatar lminhtm avatar pitsko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lmgeocoder's Issues

Original info in LMAddress

Hi! Thanks for really nice component.
Could you please consider adding full original info into LMAddress object, it could be just dictionary property. So for example I need viewport coordinate received from Google API to show on map, but it's not parsed in LMAddress and there is no ability to access original Google API response.

I can submit a quick PR for this.
Thanks.

_subLocality getting null

Hello,

I am using your library but getting _subLocality null.

Can you please check for the same.

I am using the below coordinate.

(CLLocationCoordinate2D) coordinate = (latitude = 23.010400000000001, longitude = 72.515100000000004)

Thanks,

Dulicate Declaration Issue

I installed using LMGeoCoder and gives me error duplicate declaration on each n every property and class.
I have recheck my complete code and there is not duplicate existence of this class.
Do anyone know what could be the issue?

There are some missed code parts on LMGeocoder.m file.

Hello
I found some missing code parts.

  1. on line 109 of LMGeocoder.m file
    replace
    [self parseGeocodingResponseResults:placemarks service:kLMGeocoderAppleService];
    to
    NSArray *finalResults = [self parseGeocodingResponseResults:placemarks service:kLMGeocoderAppleService];
    if (handler) {
    handler(finalResults, nil);
    }

  2. on line 207 of LMGeocoder.m file
    replace
    [self parseGeocodingResponseResults:placemarks service:kLMGeocoderAppleService];
    to
    NSArray *finalResults = [self parseGeocodingResponseResults:placemarks service:kLMGeocoderAppleService];
    if (handler) {
    handler(finalResults, nil);
    }

Geocoding Methods only work on main thread

When calling either of the following two geocoding methods on a thread other than the main thread, they fail to call their completion handlers (or do anything for that matter):

- (void)geocodeAddressString:(NSString *)addressString service:(LMGeocoderService)service completionHandler:(LMGeocodeCallback)handler;
- (void)reverseGeocodeCoordinate:(CLLocationCoordinate2D)coordinate service:(LMGeocoderService)service  completionHandler:(LMGeocodeCallback)handler;

A fix for this issue would allow for calls on background threads (e.g. when performing a background refresh, or to avoid blocking the UI). In the meantime, you may want to consider adding a documentation note in the header:

@note This method should only be called on the main thread. Calling this method on any other thread will fail.

Additionally, you may want to implement a runtime catch for this and write a warning to the log:

if (![NSThread isMainThread]) {
    NSLog(@"[LMGeocoder] Warning, geocodeAddressString:service:completionHandler: must be called on the main thread. The completion handler will not be called.");
    return;
}

How does it work without an API key?

This is amazingly easy to use. I was expecting to have to provide my own googleAPIKey. How does it work without one? Am I going to run into problems if I don't provide it? If so, then what if I were using the Apple service? Would I need an API key for that? Thank you!

By the way, here's the swift code I'm using, in case you want to add it:

LMGeocoder.sharedInstance().geocodeAddressString(addressString, service: .GoogleService, completionHandler: { (results, error) -> Void in
    if results != nil, let address = results.first as? LMAddress {
        print("Coordinate: (%f, %f)", address.coordinate.latitude, address.coordinate.longitude)
    } else if error != nil {
        print("Geocoding error: \(error.localizedDescription)")
    } else {
        print("No results found")
    }
})

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.