Giter VIP home page Giter VIP logo

swift-coordinate's Introduction

Coordinate

iOS swift经纬度转换,坐标系转换💯 WGS-84(国际标准)、GCJ-02(火星坐标) 、百度坐标相互转换

此转换库为本地坐标转换库,不需要依赖网络资源,快速转换。可在极短时间内转换大量坐标。
如果使用过程中有问题,请issue我 (。♥‿♥。)
如果觉得对你还有些用,顺手点一下star吧 (。♥‿♥。)

Demo截图

在这里插入图片描述

方法

提供以下方法

/**
 *  判断经纬度是否超出**境内
 */
static func isLocationOutOfChina(_ location: CLLocationCoordinate2D) -> Bool
 
/**
 *  将WGS-84(国际标准)转为GCJ-02(火星坐标):
 */
static func transformFromWGSToGCJ(_ wgsLoc: CLLocationCoordinate2D) -> CLLocationCoordinate2D

/**
 *  将GCJ-02(火星坐标)转为百度坐标:
 */
static func transformFromGCJToBaidu(_ p: CLLocationCoordinate2D) -> CLLocationCoordinate2D 

/**
 *  将百度坐标转为GCJ-02(火星坐标):
 */
static func transformFromBaiduToGCJ(_ p: CLLocationCoordinate2D) -> CLLocationCoordinate2D 

/**
 *  将GCJ-02(火星坐标)转为WGS-84:
 */
static func transformFromGCJToWGS(_ p: CLLocationCoordinate2D) -> CLLocationCoordinate2D 

如何使用

下载此项目,将项目中的WSCoordinate.swift添加到您的项目中。

在您需要转换的地方使用

//将WGS-84(国际标准)转为GCJ-02(火星坐标)
let WGSToGCJ = WSCoordinate.transformFromWGSToGCJ(32.0806670849, 118.9060163095)
    
// 将GCJ-02(火星坐标)转为百度坐标
let GCJToBaidu = WSCoordinate.transformFromGCJToBaidu(32.0806670849, 118.9060163095)

//将百度坐标转为GCJ-02(火星坐标)
let baiduToGCJ = WSCoordinate.transformFromBaiduToGCJ(32.0806670849, 118.9060163095)

//将GCJ-02(火星坐标)转为WGS-84
let GCJToWGS = WSCoordinate.transformFromGCJToWGS(coordinate)(32.0806670849, 118.9060163095)

方法的返回值是一个CLLocationCoordinate2D结构体,格式为

public struct CLLocationCoordinate2D {

    public var latitude: CLLocationDegrees

    public var longitude: CLLocationDegrees

    public init()

    public init(latitude: CLLocationDegrees, longitude: CLLocationDegrees)
}

通过.latitude和.longitude可得到转换后的经纬度。

如果使用过程中有问题,请issue我 (。♥‿♥。)
如果觉得对你还有些用,顺手点一下star吧 (。♥‿♥。) 你的支持是我继续的动力。

swift-coordinate's People

Contributors

zws-china avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

chinghoi

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.