Giter VIP home page Giter VIP logo

geohashobjc's Introduction

GeoHashObjC

GeoHash implementation in Objective-C for iOS and Mac OS X

About geohash:

See http://en.wikipedia.org/wiki/Geohash

Usage:

Encoding to geohash:

  • (NSString *) encodeGeohash:(CLLocationCoordinate2D) coordinate;
  • (NSString *) encodeGeohash:(CLLocationCoordinate2D) coordinate withPrecision:(NSUInteger) precision;
  • (NSString ) encodeGeohashFromLocation:(CLLocation) location;
  • (NSString ) encodeGeohashFromLocation:(CLLocation) location withPrecision:(NSUInteger) precision;

These methods will return a geohash for the given coordinate/location. The methods with the precision parameter allow you to define the precision of the resulting geocode, the ones without that parameter use a precision of 12.

Decoding a geohash:

  • (GHLocationRect) decodeGeohash:(NSString *) geohash;
  • (CLRegion *) decodeGeohashAsRegion:(NSString *) geohash;

Since a geohash does not denote a point but a square region, these methods do not return coordinates. The first method returns a GHLocationRect, which is a struct containing to CLLocationCoordinate2D entries, one for the north-eastern coordinate and one for the south-western coordinate. The method return a CLRegion transforms the GHLocationRect into a circular region of about the same size as the rectangle.

Expanding the size of a geohash:

  • (NSArray *) adjacentGeohashes:(NSString *) geohash includeSelf:(BOOL) include;

The resulting array will contain the geohashes which are adjacent to the given geohash. These will be 8 geohashes for north-east, north, north-west, west, south-west, south, south-east and east. If inculde is YES, the given geohosh will be included in the resulting array.

For use with databases (without spatial search, e.g. DynamoDB):

In addition to the latitude and longitude values you should store the correspondin geohashes of the entries. The client can then compute the geohash for a location, find the adjacent geohashes and perform a search for those hashes on the database. The radius of the search can be controlled by the precision of the geohash.

Credits:

This implementation is based on https://github.com/davetroy/geohash-js by Dave Troy (https://github.com/davetroy)

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.