GithubHelp home page GithubHelp logo

ahlocationmanager's Introduction

AHLocationManager

Swift 定位权限封装,坐标转换

功能列表

  • 获取系统经纬度坐标
  • GPS国际标准,高德坐标,百度坐标相互转换
  • 定位权限被拒弹框提示

使用方法

1,将源文件AHLocationManager.swift引入项目中
2,添加info.plist 描述
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>App需要您的同意,才能访问位置以便xxx</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>App需要您的同意,才能访问位置以便xxx</string>
3,调用
        AHLocationManager.shared.startPositioning(self)
        AHLocationManager.shared.locationType = .BD
        AHLocationManager.shared.postionUpdateClosure = {[weak self] (locModel) in
            if locModel.locationError != nil {
                self?.locationLabel.text = "定位失败"
            }else{
                if let coordinate = locModel.coordinate{
                    self?.latLabel.text = "\(coordinate.latitude)"
                    self?.longLabel.text = "\(coordinate.longitude)"
                }
                
                if let place = locModel.clplacemark {
                    self?.locationLabel.text = "\(place.administrativeArea ?? "")\(place.locality ?? "")\(place.subLocality ?? "")\(place.thoroughfare ?? "")\(place.name ?? "")"
                }
                
            }
        }
enum AHLocationType{
    /// WGS-84:是国际标准,GPS坐标(Google Earth使用、或者GPS模块)
    case WGS
    /// GCJ-02:**坐标偏移标准,Google Map、高德、腾讯使用
    case GCJ
    /// BD-09 :百度坐标偏移标准,Baidu Map使用
    case BD
    
}

通过locationType 可指定返回经纬度类型,默认返回的经纬度为WGS-84

坐标转换参考https://www.jianshu.com/p/abdb35b0ba78 坐标转换可能存在一定误差,使用时自行斟酌

ahlocationmanager's People

Contributors

aidahe avatar

Watchers

James Cloos 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.