Giter Site home page Giter Site logo

locationformatter's Introduction

Swift Latest Release Swift Package Manager License

LocationFormatter

This package provides some Formatters that convert between coordinates and their textual representations.

Usage

Please see the documentation for more detailed usage instructions.

LocationCoordinateFormatter

This is the primary formatter for converting coordinates. It utilizes additional formatters for specific formats.

LocationCoordinateFormatter provides a variety of configuration options for customizing both the string output and parsing coordinates from strings.

Converting coordinates to strings

import LocationFormatter

let coordinate = CLLocationCoordinate2D(latitude: 48.11638, longitude: -122.77527)
let formatter = LocationCoordinateFormatter()

// Decimal Degrees (DD)
formatter.format = .decimalDegrees
formatter.string(from: coordinate) // "48.11638° N, 122.74231° W"

// Degrees Decimal Minutes (DDM)
formatter.format = .degreesDecimalMinutes
formatter.string(from: coordinate) // "48° 06.983' N, 122° 46.516' W"

// Degrees Minutes Seconds (DMS)
formatter.format = .degreesMinutesSeconds
formatter.string(from: coordinate) // "48° 6' 59" N, 122° 46' 31" W"

// Universal Trans Mercator (UTM)
formatter.format = .utm
formatter.string(from: coordinate) // "10U 516726m E 5329260m N"

Converting strings to coordinates

import LocationFormatter

let formatter = LocationCoordinateFormatter() 

// Decimal Degrees (DD)
formatter.format = .decimalDegrees
try formatter.coordinate(from: "48.11638° N, 122.74231° W") // (48.11638, -122.77527)

// Degrees Decimal Minutes (DDM)
formatter.format = .degreesDecimalMinutes
try formatter.coordinate(from: "48° 06.983' N, 122° 46.516' W") // (48.11638, -122.77527)

// Degrees Minutes Seconds (DMS)
formatter.format = .degreesMinutesSeconds
try formatter.coordinate(from: "48° 6' 59\" N, 122° 46' 31\" W") // (48.11638, -122.77527)

// Universal Trans Mercator (UTM)
formatter.format = .utm
try formatter.coordinate(from: "10U 516726m E 5329260m N") // (48.11638, -122.77527)

Extensions

String+Location

Extends String with a convenience function to parse a coordinate from a string using all supported format.

import Location

"48.11638 °N, 122.74231° W".coordinate() // (48.11638, -122.77527)
"48° 06.983' N, 122° 46.516' W".coordinate() // (48.11638, -122.77527)
"48° 6' 59\" N, 122° 46' 31\" W".coordinate() // (48.11638, -122.77527)
"10U 516726m E 5329260m N".coordinate() // (48.11638, -122.77527)

Dependencies

UTMConversion

Swift-DocC Plugin

locationformatter's People

Contributors

hholtmann avatar hishma 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.