Giter VIP home page Giter VIP logo

geocore-swift's Introduction

GeocoreKit

This is a very early version.

GeocoreKit is a pure Swift framework for accessing Geocore API server.

Installation

GeocoreKit is available either through CocoaPods or Carthage. To install it using CocoaPods simply add the following line to your Podfile:

pod "GeocoreKit"

To install it using Carthage, add the following line to your Cartfile:

github "geocore/geocore-swift"

Basic Usage

Before using the library, the easiest way to setup the connection is by adding following keys to the Info.plist file:

Key name Value
GeocoreBaseURL Base URL of the Geocore API
GeocoreProjectId ID of the project provided by MapMotion

By importing GeocoreKit, the library's main singleton instance is accesible using sharedInstance static member as shown below:

import GeocoreKit

// ....

let geocore = Geocore.sharedInstance

Once you have configured the connection, the easiest way to login to Geocore is by using loginWithDefaultUser available from the Geocore singleton object. Most functions provided by Geocore return Promise object provided by PromiseKit.

Geocore.sharedInstance.loginWithDefaultUser().then { accessToken -> Void in
    println("Logged in to Geocore successfully, with access token = \(accessToken)")
}

Snippets

Here's a basic example showing how to chain promises to:

  • Initialize the framework.
  • Login to Geocore.
  • Fetch user object.
  • Fetch some places nearest to a coordinate.
import PromiseKit
import GeocoreKit

Geocore.sharedInstance
    .setup(baseURL: GEOCORE_BASEURL, projectId: GEOCORE_PROJECTID)
    .login(userId: GEOCORE_USERID, password: GEOCORE_USERPASSWORD)
    .then { accessToken -> Promise<GeocoreUser> in
        print("Access Token = \(accessToken)")
        return GeocoreUser.get(GEOCORE_USERID)
    }
    .then { user -> Promise<[GeocorePlace]> in
        print("--- The user as promised:")
        print("Id = \(user.id!), Name = \(user.name!)")
        return GeocorePlaceQuery()
            .withCenter(latitude: 35.666, longitude: 139.7126)
            .nearest()
    }
    .then { places -> Void in
        print("--- Some places as promised:")
        for place in places {
            print("Id = \(place.id!), Name = \(place.name!), Point = (\(place.point!.latitude!), \(place.point!.longitude!))")
        }
    }
    .catch { error in
        print("--- Cannot fulfill promise because of : \(error)")
    }

Following example shows how to get places within a specified rectangle:

GeocorePlaceQuery()
    .withRectangle(
        minimumLatitude: 35.66617440081799,
        minimumLongitude: 139.7126117348629,
        maximumLatitude: 35.67753978462231,
        maximumLongitude: 139.72917705773887)
    .withinRectangle()
    .then { places -> Void in
        for place in places {
            print("Id = \(place.id), Name = \(place.name), Point = (\(place.point?.latitude), \(place.point?.longitude))")
        }
    }
    .catch { error in
        print("--- Cannot fulfill promise because of : \(error)")
    }

Notes

geocore-swift's People

Contributors

mpurbo avatar settl avatar

Watchers

James Cloos avatar  avatar  avatar Josh Deckman avatar Julien Hora avatar

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.