Commit 6055b94b authored by lujunye's avatar lujunye

地图

parent b9d654f8
......@@ -34,7 +34,7 @@ zxcvbnm
import UIKit
import ESTabBarController_swift
import JZLocationConverterSwift
@available(iOS 10.0, *)
@UIApplicationMain
......@@ -55,6 +55,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate,loginDelegate, UITabBarCon
setting_ShareSDK()
JZLocationConverter.start { (error) in
if error != nil {
print("失败")
}else {
print("成功")
}
}
return true
}
......
{
"images" : [
{
"filename" : "locIcon.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "locIcon@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "locIcon@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
......@@ -30,6 +30,7 @@ class cityListDataModel: Mappable {
var city_id : Int?
var name_en : String?
required init?( map: Map) {
}
......@@ -301,16 +302,15 @@ class citySearchDataModel: Mappable {
}
}
class citySearchDataPoiModel: Mappable {
var area:String?//地址所属区(县),示例:⻰华区
var uid:String? //地址uid
var name:String?// 地址名称,示例:深圳北站
var address:String? // 地址详情,示例:深圳市⻰华区致远中路28号
var name:String?// 地址名称,示例:深圳北站
var city:String?//地址所属城市名称, 示例:深圳市
var city_id:Int?//地址所属城市ID,示例:1002
var area:String?//地址所属区(县),示例:⻰华区
var distance:String? //距离(将返回与输入参数中经纬度的距离,如果输入参数中没有传经纬度 则返回空)
var location:citySearchDataPoiLocationModel?//地址经纬度(wgs84坐标系)
var children:Array<citySearchDataPoiChildrenModel>?//可选子节点地址
var city_id:Int?//地址所属城市ID,示例:1002
required init?( map: Map) {
......@@ -323,7 +323,8 @@ class citySearchDataPoiModel: Mappable {
city_id <- map["city_id"]
area <- map["area"]
distance <- map["distance"]
children <- map["children"]
location <- map["location"]
}
}
class citySearchDataPoiLocationModel: Mappable {
......
......@@ -7,18 +7,69 @@
//
import UIKit
protocol HuoLaLaDiZhiCellDelegate {
func HuoLaLaDiZhiCellBtnClick(model:citySearchDataPoiChildrenModel,cityStr:String)
}
class HuoLaLaDiZhiCell: UITableViewCell {
var delegate:HuoLaLaDiZhiCellDelegate?
var cityStr:String = ""
@IBOutlet weak var btmH: NSLayoutConstraint!
@IBOutlet weak var marginValue: NSLayoutConstraint!
@IBOutlet weak var btnViewBG: UIView!
@IBOutlet weak var btnViewH: NSLayoutConstraint!
@IBOutlet weak var contentLbl: UILabel!
@IBOutlet weak var nameLbl: UILabel!
var children:Array<citySearchDataPoiChildrenModel>?
override func awakeFromNib() {
super.awakeFromNib()
self.selectionStyle = .none
// Initialization code
}
override func layoutSubviews() {
super.layoutSubviews()
for item in btnViewBG.subviews {
item.removeFromSuperview()
}
if children != nil && children!.count > 0 {
for i in 0 ..< children!.count {
setLocUI(index: i, bg: btnViewBG!)
}
}
}
func setLocUI(index:Int,bg:UIView){
let item = children![index]
let width = fullScreenWidth - 40 - bg.frame.minX
let w = width / 3
let cols = 3
let col = index % cols
let row = index / cols
let shopX = CGFloat(col) * (w + 10)
let shopY = CGFloat(row) * (30 + 10)
let btn = UIButton(frame: CGRect(x: shopX , y: shopY , width: w, height: 30))
btn.addTarget(self, action: #selector(locSelect(sender:)), for: .touchUpInside)
btn.tag = index
btn.layer.borderColor = UIColor(named: "提示语字体颜色")?.cgColor
btn.layer.borderWidth = 1
btn.layer.cornerRadius = 3
btn.layer.masksToBounds = true
btn.setTitle(item.address, for: .normal)
btn.titleLabel?.font = UIFont.systemFont(ofSize: 11)
btn.setTitleColor(UIColor(named: "灰色字体颜色"), for: .normal)
bg.addSubview(btn)
}
@objc func locSelect(sender:UIButton){
delegate?.HuoLaLaDiZhiCellBtnClick(model: children![sender.tag],cityStr: cityStr)
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
......
......@@ -19,10 +19,7 @@
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="SVj-as-s8v">
<rect key="frame" x="15" y="15" width="298" height="18.5"/>
<constraints>
<constraint firstAttribute="height" constant="18.5" id="X4e-gb-qKp"/>
</constraints>
<rect key="frame" x="37" y="15.5" width="276" height="18"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" name="标题字颜色"/>
<nil key="highlightedColor"/>
......@@ -31,11 +28,11 @@
<rect key="frame" x="15" y="205" width="313" height="1"/>
<color key="backgroundColor" name="灰色分界线"/>
<constraints>
<constraint firstAttribute="height" constant="1" id="NXr-Wv-9vF"/>
<constraint firstAttribute="height" constant="1" id="fLK-EK-WzV"/>
</constraints>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" usesAttributedText="YES" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="xvf-JN-rSb">
<rect key="frame" x="15" y="38.5" width="298" height="151.5"/>
<rect key="frame" x="37" y="38.5" width="276" height="121.5"/>
<attributedString key="attributedText">
<fragment content="Label">
<attributes>
......@@ -47,29 +44,53 @@
</attributedString>
<nil key="highlightedColor"/>
</label>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="locIcon" translatesAutoresizingMaskIntoConstraints="NO" id="LiS-tq-479">
<rect key="frame" x="15" y="17" width="12" height="14.5"/>
<constraints>
<constraint firstAttribute="width" constant="12" id="lvI-ij-HIS"/>
<constraint firstAttribute="height" constant="14.5" id="xkU-7I-dJg"/>
</constraints>
</imageView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="hvc-4C-RNf">
<rect key="frame" x="37" y="170" width="271" height="30"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="Qwu-H6-xxW"/>
</constraints>
</view>
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="3s8-3x-dnL" secondAttribute="trailing" id="24Y-o3-crE"/>
<constraint firstAttribute="bottom" secondItem="3s8-3x-dnL" secondAttribute="bottom" id="Blx-oo-mcC"/>
<constraint firstItem="xvf-JN-rSb" firstAttribute="top" secondItem="SVj-as-s8v" secondAttribute="bottom" constant="5" id="RhK-r4-M8n"/>
<constraint firstItem="SVj-as-s8v" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="15" id="WF1-iZ-ieb"/>
<constraint firstItem="SVj-as-s8v" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="15" id="goD-EA-cfh"/>
<constraint firstItem="xvf-JN-rSb" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="15" id="jTf-fa-heK"/>
<constraint firstAttribute="trailing" secondItem="SVj-as-s8v" secondAttribute="trailing" constant="15" id="l0H-rf-a8U"/>
<constraint firstItem="3s8-3x-dnL" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="15" id="rSn-7l-jpO"/>
<constraint firstItem="3s8-3x-dnL" firstAttribute="top" secondItem="xvf-JN-rSb" secondAttribute="bottom" constant="15" id="yQs-Ud-Iuf"/>
<constraint firstAttribute="trailing" secondItem="xvf-JN-rSb" secondAttribute="trailing" constant="15" id="zMV-5p-xYy"/>
<constraint firstItem="xvf-JN-rSb" firstAttribute="top" secondItem="SVj-as-s8v" secondAttribute="bottom" constant="5" id="8FH-0u-H8c"/>
<constraint firstItem="3s8-3x-dnL" firstAttribute="top" secondItem="hvc-4C-RNf" secondAttribute="bottom" constant="5" id="8Qm-f1-nhw"/>
<constraint firstAttribute="trailing" secondItem="3s8-3x-dnL" secondAttribute="trailing" id="BSQ-wj-j2r"/>
<constraint firstItem="hvc-4C-RNf" firstAttribute="leading" secondItem="SVj-as-s8v" secondAttribute="leading" id="JgM-e2-dtt"/>
<constraint firstItem="SVj-as-s8v" firstAttribute="leading" secondItem="LiS-tq-479" secondAttribute="trailing" constant="10" id="QJF-WJ-nWf"/>
<constraint firstItem="LiS-tq-479" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="15" id="SJE-6Z-l9N"/>
<constraint firstItem="xvf-JN-rSb" firstAttribute="leading" secondItem="SVj-as-s8v" secondAttribute="leading" id="UPJ-1G-QgX"/>
<constraint firstAttribute="trailingMargin" secondItem="hvc-4C-RNf" secondAttribute="trailing" id="Un6-UV-7MU"/>
<constraint firstAttribute="bottom" secondItem="3s8-3x-dnL" secondAttribute="bottom" id="Wzk-G0-TbQ"/>
<constraint firstItem="SVj-as-s8v" firstAttribute="centerY" secondItem="LiS-tq-479" secondAttribute="centerY" id="e4E-tj-2qG"/>
<constraint firstItem="hvc-4C-RNf" firstAttribute="top" secondItem="xvf-JN-rSb" secondAttribute="bottom" constant="10" id="jTv-GL-HZy"/>
<constraint firstAttribute="trailing" secondItem="SVj-as-s8v" secondAttribute="trailing" constant="15" id="x9A-aJ-BTL"/>
<constraint firstItem="3s8-3x-dnL" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="15" id="yNm-Ld-1bK"/>
<constraint firstAttribute="trailing" secondItem="xvf-JN-rSb" secondAttribute="trailing" constant="15" id="z4V-iH-Tu5"/>
<constraint firstItem="LiS-tq-479" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="17" id="z6R-Kr-FEd"/>
</constraints>
</tableViewCellContentView>
<viewLayoutGuide key="safeArea" id="njF-e1-oar"/>
<connections>
<outlet property="btmH" destination="8Qm-f1-nhw" id="Unk-ez-xHr"/>
<outlet property="btnViewBG" destination="hvc-4C-RNf" id="w3G-ST-cIG"/>
<outlet property="btnViewH" destination="Qwu-H6-xxW" id="dzy-Mc-iGb"/>
<outlet property="contentLbl" destination="xvf-JN-rSb" id="xG8-yJ-JaO"/>
<outlet property="marginValue" destination="jTv-GL-HZy" id="OMV-xy-gHi"/>
<outlet property="nameLbl" destination="SVj-as-s8v" id="jan-yT-jXv"/>
</connections>
<point key="canvasLocation" x="137.68115942028987" y="168.75"/>
</tableViewCell>
</objects>
<resources>
<image name="locIcon" width="12" height="14.5"/>
<namedColor name="9A9A9A">
<color red="0.60392156862745094" green="0.60392156862745094" blue="0.60392156862745094" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
......
......@@ -61,12 +61,12 @@
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" semanticContentAttribute="forceRightToLeft" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ADf-bf-b5w">
<rect key="frame" x="56" y="13.5" width="60" height="18"/>
<rect key="frame" x="46" y="13.5" width="80" height="18"/>
<constraints>
<constraint firstAttribute="width" constant="60" id="1ot-j5-ieI"/>
<constraint firstAttribute="width" constant="80" id="1ot-j5-ieI"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<state key="normal" title="广州" image="xiala">
<state key="normal" title=" " image="xiala">
<color key="titleColor" name="标题字颜色"/>
</state>
<connections>
......@@ -90,7 +90,7 @@
<constraint firstAttribute="trailing" secondItem="QHB-sv-BsU" secondAttribute="trailing" id="NNc-Tm-Iye"/>
<constraint firstItem="ADf-bf-b5w" firstAttribute="centerY" secondItem="gLT-4M-bfs" secondAttribute="centerY" id="OYn-qq-QJP"/>
<constraint firstItem="mc4-mS-8P7" firstAttribute="leading" secondItem="gLT-4M-bfs" secondAttribute="leading" id="QbR-Uv-mj9"/>
<constraint firstItem="ADf-bf-b5w" firstAttribute="leading" secondItem="mc4-mS-8P7" secondAttribute="trailing" constant="10" id="Sy5-bj-ulv"/>
<constraint firstItem="ADf-bf-b5w" firstAttribute="leading" secondItem="mc4-mS-8P7" secondAttribute="trailing" id="Sy5-bj-ulv"/>
<constraint firstAttribute="bottom" secondItem="QHB-sv-BsU" secondAttribute="bottom" id="rT4-u8-EiK"/>
<constraint firstItem="LY7-wU-8ih" firstAttribute="centerY" secondItem="gLT-4M-bfs" secondAttribute="centerY" id="tdR-GU-ZsW"/>
<constraint firstAttribute="height" constant="45" id="ze9-Uw-zVl"/>
......
......@@ -28,6 +28,7 @@ pod 'ViewAnimator'
pod 'SkeletonView'
pod 'SnapKit'
pod 'LGButton'
pod 'JZLocationConverterSwift'
pod 'WYAutoLayout'
end
This source diff could not be displayed because it is too large. You can view the blob instead.
//
// JZAreaManager.swift
// JZLocationConverterDemo
//
// Created by jack zhou on 23/08/2017.
// Copyright © 2017 Jack. All rights reserved.
//
import Foundation
import CoreLocation
public enum JZFileError: Error {
case FileNotFound
case EmptyData
case invalidData
}
open class JZAreaManager {
private(set) var points:Array<Array<Double>>?
fileprivate let queue = DispatchQueue(label: "JZ.LocationConverter.AreaManager")
public static let `default`: JZAreaManager = {
return JZAreaManager()
}()
public static func start(finished:((_ error:JZFileError?) -> Void)?) {
guard let filePath = Bundle(for:JZAreaManager.self).path(forResource: "GCJ02", ofType: "json") else {
DispatchQueue.main.async {
if finished != nil {
finished!(JZFileError.FileNotFound)
}
}
return
}
start(filePath: filePath) { error in
if finished != nil{
finished!(error)
}
}
}
public static func start(filePath:String!,finished:((_ error:JZFileError?) -> Void)?) {
JZAreaManager.default.queue.async {
guard let jsonString = try? String(contentsOfFile: filePath) else {
DispatchQueue.main.async {
if finished != nil {
finished!(JZFileError.EmptyData)
}
}
return
}
guard let data = jsonString.data(using: .utf8) else {
DispatchQueue.main.async {
if finished != nil {
finished!(JZFileError.invalidData)
}
}
return
}
guard let array = try? JSONSerialization.jsonObject(with: data, options: []) else {
DispatchQueue.main.async {
if finished != nil {
finished!(JZFileError.invalidData)
}
}
return
}
JZAreaManager.default.points = array as? Array<Array<Double>>
DispatchQueue.main.async {
if finished != nil {
finished!(nil)
}
}
}
}
public func isOutOfArea(gcj02Point:CLLocationCoordinate2D,result:@escaping ((_ result:Bool)->Void)) -> Void {
self.queue.async {
var flag = false
if JZAreaManager.default.points != nil {
let length = (JZAreaManager.default.points?.count)!
for idx in 0 ..< length {
let nextIdx = (idx + 1) == length ? 0 : idx + 1
let edgePoint = JZAreaManager.default.points![idx]
let nextPoint = JZAreaManager.default.points![nextIdx]
let pointX = edgePoint[1]
let pointY = edgePoint[0]
let nextPointX = nextPoint[1]
let nextPointY = nextPoint[0]
if (gcj02Point.longitude == pointX && gcj02Point.latitude == pointY) ||
(gcj02Point.longitude == nextPointX && gcj02Point.latitude == nextPointY) {
flag = true
}
if((nextPointY < gcj02Point.latitude && pointY >= gcj02Point.latitude) ||
(nextPointY >= gcj02Point.latitude && pointY < gcj02Point.latitude)) {
let thX = nextPointX + (gcj02Point.latitude - nextPointY) * (pointX - nextPointX) / (pointY - nextPointY)
if(thX == gcj02Point.longitude) {
flag = true
break
}
if(thX > gcj02Point.longitude) {
flag = !flag
}
}
}
}
DispatchQueue.main.async {
result(!flag)
}
}
}
}
//
// JZLocationConverter.swift
// JZLocationConverter-Swift
//
// Created by jack zhou on 21/07/2017.
// Copyright © 2017 Jack. All rights reserved.
//
import Foundation
import CoreLocation
extension CLLocationCoordinate2D {
struct JZConstant {
static let A = 6378245.0
static let EE = 0.00669342162296594323
}
func gcj02Offset() -> CLLocationCoordinate2D {
let x = self.longitude - 105.0
let y = self.latitude - 35.0
let latitude = (-100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * sqrt(fabs(x))) +
((20.0 * sin(6.0 * x * .pi) + 20.0 * sin(2.0 * x * .pi)) * 2.0 / 3.0) +
((20.0 * sin(y * .pi) + 40.0 * sin(y / 3.0 * .pi)) * 2.0 / 3.0) +
((160.0 * sin(y / 12.0 * .pi) + 320 * sin(y * .pi / 30.0)) * 2.0 / 3.0)
let longitude = (300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * sqrt(fabs(x))) +
((20.0 * sin(6.0 * x * .pi) + 20.0 * sin(2.0 * x * .pi)) * 2.0 / 3.0) +
((20.0 * sin(x * .pi) + 40.0 * sin(x / 3.0 * .pi)) * 2.0 / 3.0) +
((150.0 * sin(x / 12.0 * .pi) + 300.0 * sin(x / 30.0 * .pi)) * 2.0 / 3.0)
let radLat = 1 - self.latitude / 180.0 * .pi;
var magic = sin(radLat);
magic = 1 - JZConstant.EE * magic * magic
let sqrtMagic = sqrt(magic);
let dLat = (latitude * 180.0) / ((JZConstant.A * (1 - JZConstant.EE)) / (magic * sqrtMagic) * .pi);
let dLon = (longitude * 180.0) / (JZConstant.A / sqrtMagic * cos(radLat) * .pi);
return CLLocationCoordinate2DMake(dLat, dLon);
}
}
open class JZLocationConverter {
fileprivate let queue = DispatchQueue(label: "JZ.LocationConverter.Converter")
public static let `default`: JZLocationConverter = {
return JZLocationConverter()
}()
public static func start(filePath:String!,finished:((_ error:JZFileError?) -> Void)?) {
JZAreaManager.start(filePath: filePath, finished: finished)
}
public static func start(finished:((_ error:JZFileError?) -> Void)?) {
JZAreaManager.start(finished: finished)
}
}
//GCJ02
extension JZLocationConverter {
fileprivate func gcj02Encrypt(_ wgs84Point:CLLocationCoordinate2D,result:@escaping (_ gcj02Point:CLLocationCoordinate2D) -> Void) {
self.queue.async {
let offsetPoint = wgs84Point.gcj02Offset()
let resultPoint = CLLocationCoordinate2DMake(wgs84Point.latitude + offsetPoint.latitude, wgs84Point.longitude + offsetPoint.longitude)
JZAreaManager.default.isOutOfArea(gcj02Point: resultPoint, result: { (isOut:Bool) in
DispatchQueue.main.async {
if isOut {
result(wgs84Point)
}else {
result(resultPoint)
}
}
})
}
}
fileprivate func gcj02Decrypt(_ gcj02Point:CLLocationCoordinate2D,result:@escaping (_ wgs84Point:CLLocationCoordinate2D) -> Void) {
JZAreaManager.default.isOutOfArea(gcj02Point: gcj02Point, result: { (isOut:Bool) in
if isOut {
DispatchQueue.main.async {
result(gcj02Point)
}
}else {
self.gcj02Encrypt(gcj02Point) { (mgPoint:CLLocationCoordinate2D) in
self.queue.async {
let resultPoint = CLLocationCoordinate2DMake(gcj02Point.latitude * 2 - mgPoint.latitude,gcj02Point.longitude * 2 - mgPoint.longitude)
DispatchQueue.main.async {
result(resultPoint)
}
}
}
}
})
}
}
//BD09
extension JZLocationConverter {
fileprivate func bd09Encrypt(_ gcj02Point:CLLocationCoordinate2D,result:@escaping (_ bd09Point:CLLocationCoordinate2D) -> Void) {
self.queue.async {
let x = gcj02Point.longitude
let y = gcj02Point.latitude
let z = sqrt(x * x + y * y) + 0.00002 * sin(y * .pi);
let theta = atan2(y, x) + 0.000003 * cos(x * .pi);
let resultPoint = CLLocationCoordinate2DMake(z * sin(theta) + 0.006, z * cos(theta) + 0.0065)
DispatchQueue.main.async {
result(resultPoint)
}
}
}
fileprivate func bd09Decrypt(_ bd09Point:CLLocationCoordinate2D,result:@escaping (_ gcj02Point:CLLocationCoordinate2D) -> Void) {
self.queue.async {
let x = bd09Point.longitude - 0.0065
let y = bd09Point.latitude - 0.006
let z = sqrt(x * x + y * y) - 0.00002 * sin(y * .pi);
let theta = atan2(y, x) - 0.000003 * cos(x * .pi);
let resultPoint = CLLocationCoordinate2DMake(z * sin(theta), z * cos(theta))
DispatchQueue.main.async {
result(resultPoint)
}
}
}
}
extension JZLocationConverter {
public func wgs84ToGcj02(_ wgs84Point:CLLocationCoordinate2D,result:@escaping (_ gcj02Point:CLLocationCoordinate2D) -> Void) {
self.gcj02Encrypt(wgs84Point, result: result)
}
public func wgs84ToBd09(_ wgs84Point:CLLocationCoordinate2D,result:@escaping (_ bd09Point:CLLocationCoordinate2D) -> Void) {
self.gcj02Encrypt(wgs84Point) { (gcj02Point:CLLocationCoordinate2D) in
self.bd09Encrypt(gcj02Point, result: result);
}
}
public func gcj02ToWgs84(_ gcj02Point:CLLocationCoordinate2D,result:@escaping (_ wgs84Point:CLLocationCoordinate2D) -> Void) {
self.gcj02Decrypt(gcj02Point, result: result)
}
public func gcj02ToBd09(_ gcj02Point:CLLocationCoordinate2D,result:@escaping (_ bd09Point:CLLocationCoordinate2D) -> Void) {
self.bd09Encrypt(gcj02Point, result: result);
}
public func bd09ToGcj02(_ bd09Point:CLLocationCoordinate2D,result:@escaping (_ gcj02Point:CLLocationCoordinate2D) -> Void) {
self.bd09Decrypt(bd09Point, result: result)
}
public func bd09ToWgs84(_ bd09Point:CLLocationCoordinate2D,result:@escaping (_ wgs84Point:CLLocationCoordinate2D) -> Void) {
self.bd09Decrypt(bd09Point) { (gcj02Point:CLLocationCoordinate2D) in
self.gcj02Decrypt(gcj02Point, result: result);
}
}
}
WGS-84世界标准坐标、GCJ-02中国国测局(火星坐标)、BD-09百度坐标系转换
===================
[![iOS](https://img.shields.io/badge/iOS-8.0%2B-green.svg)](https://apple.com)
[![Swift](https://img.shields.io/badge/Swift-3.1-orange.svg)](https://swift.org)
[![Xcode](https://img.shields.io/badge/Xcode-8.3-blue.svg)](https://developer.apple.com/xcode)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![CocoaPods](https://img.shields.io/cocoapods/v/JZLocationConverter-Swift.svg)](https://cocoapods.org)
# Demo
<img src="1.gif" width="50%" height="50%">
# 使用
### 支持 [Carthage](https://github.com/Carthage/Carthage),添加以下代码到你的Cartfile文件中:
```
github "JackZhouCn/JZLocationConverter-Swift"
```
## 1、在APP启动时加载[大陆边境线数据](#关于大陆边境线数据):
```swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
JZLocationConverter.start(filePath: Bundle(for:JZAreaManager.self).path(forResource: "GCJ02", ofType: "json")) { (error:JZFileError?) in
if error != nil {
print("失败")
}else {
print("成功")
}
}
return true
}
```
## 2、转换方法都在转换工具单例类内
```swift
JZLocationConverter.default
```
## 3、目前有:
### WGS-84 -> GCJ-02
### 此接口当输入坐标为中国大陆以外时,仍旧返回WGS-84坐标
```swift
public func wgs84ToGcj02(_ wgs84Point:CLLocationCoordinate2D,result:@escaping (_ gcj02Point:CLLocationCoordinate2D) -> Void)
```
### GCJ-02 -> WGS-84
### 此接口有1-2米左右的误差,需要精确的场景慎用
```swift
public func gcj02ToWgs84(_ gcj02Point:CLLocationCoordinate2D,result:@escaping (_ wgs84Point:CLLocationCoordinate2D) -> Void)
```
### WGS-84 -> BD-09
```swift
public func wgs84ToBd09(_ wgs84Point:CLLocationCoordinate2D,result:@escaping (_ bd09Point:CLLocationCoordinate2D) -> Void)
```
### BD-09 -> WGS-84
```swift
public func bd09ToWgs84(_ bd09Point:CLLocationCoordinate2D,result:@escaping (_ wgs84Point:CLLocationCoordinate2D) -> Void)
```
## GCJ-02 -> BD-09
```swift
public func gcj02ToBd09(_ gcj02Point:CLLocationCoordinate2D,result:@escaping (_ bd09Point:CLLocationCoordinate2D) -> Void)
```
### BD-09 -> GCJ-02
### 此接口有1-2米左右的误差,需要精确的场景慎用
```swift
public func bd09ToGcj02(_ bd09Point:CLLocationCoordinate2D,result:@escaping (_ gcj02Point:CLLocationCoordinate2D) -> Void)
```
# 关于大陆边境线数据
### 1、默认的边境线数据位于项目的GCJ02.json文件中
### 2、默认的边境线数据来自「百度地图」API并转换到GCJ02
### 3、如果你需要使用自己的边境线数据(需要GCJ02坐标),只需要在[启动](#1%E5%9C%A8app%E5%90%AF%E5%8A%A8%E6%97%B6%E5%8A%A0%E8%BD%BD%E8%BE%B9%E5%A2%83%E7%BA%BF%E6%95%B0%E6%8D%AE)时加载自己的数据即可
### 4、默认的大陆边境线数据范围
<img src="FAF6739F-A027-411B-BAA8-4B6B1485E374.png" width="100%" height="100%">
This diff is collapsed.
......@@ -14,9 +14,9 @@
buildForArchiving = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "68494F30B4A13F8E5E88BCCAEC25B0A4"
BuildableName = "Realm.framework"
BlueprintName = "Realm"
BlueprintIdentifier = "8A1DC7C9992BBE1D1BB615909F3A1A42"
BuildableName = "JZLocationConverterSwift.framework"
BlueprintName = "JZLocationConverterSwift"
ReferencedContainer = "container:Pods.xcodeproj">
</BuildableReference>
</BuildActionEntry>
......
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1100"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForAnalyzing = "YES"
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "782725687624F8665247B84AB581BEB1"
BuildableName = "RealmSwift.framework"
BlueprintName = "RealmSwift"
ReferencedContainer = "container:Pods.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
buildConfiguration = "Debug"
allowLocationSimulation = "YES">
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES"
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
......@@ -8,158 +8,101 @@
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>0</integer>
</dict>
<key>BabyBluetooth.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>21</integer>
</dict>
<key>CryptoSwift.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>1</integer>
</dict>
<key>Dollar.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>2</integer>
</dict>
<key>ESTabBarController-swift.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>3</integer>
</dict>
<key>Hue.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>4</integer>
</dict>
<key>IQKeyboardManagerSwift.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>5</integer>
</dict>
<key>JZLocationConverterSwift.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
</dict>
<key>Kingfisher.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>6</integer>
</dict>
<key>LGButton.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>7</integer>
</dict>
<key>MJRefresh.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>8</integer>
</dict>
<key>ObjectMapper.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>9</integer>
</dict>
<key>Pods-GeliBusinessPlatform.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>10</integer>
</dict>
<key>ReachabilitySwift.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>11</integer>
</dict>
<key>Realm.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>12</integer>
</dict>
<key>RealmSwift.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>13</integer>
</dict>
<key>SVProgressHUD.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>22</integer>
</dict>
<key>SkeletonView.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>14</integer>
</dict>
<key>SnapKit.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>15</integer>
</dict>
<key>SwiftDate.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>16</integer>
</dict>
<key>SwifterSwift.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>17</integer>
</dict>
<key>SwiftyJSON.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>18</integer>
</dict>
<key>ViewAnimator.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>19</integer>
</dict>
<key>WYAutoLayout.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>20</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
......
......@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.3.1</string>
<string>1.3.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>${PRODUCT_BUNDLE_IDENTIFIER}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>${CURRENT_PROJECT_VERSION}</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
#import <Foundation/Foundation.h>
@interface PodsDummy_JZLocationConverterSwift : NSObject
@end
@implementation PodsDummy_JZLocationConverterSwift
@end
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#else
#ifndef FOUNDATION_EXPORT
#if defined(__cplusplus)
#define FOUNDATION_EXPORT extern "C"
#else
#define FOUNDATION_EXPORT extern
#endif
#endif
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#else
#ifndef FOUNDATION_EXPORT
#if defined(__cplusplus)
#define FOUNDATION_EXPORT extern "C"
#else
#define FOUNDATION_EXPORT extern
#endif
#endif
#endif
FOUNDATION_EXPORT double JZLocationConverterSwiftVersionNumber;
FOUNDATION_EXPORT const unsigned char JZLocationConverterSwiftVersionString[];
CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/JZLocationConverterSwift
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS -suppress-warnings
PODS_BUILD_DIR = ${BUILD_DIR}
PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
PODS_ROOT = ${SRCROOT}
PODS_TARGET_SRCROOT = ${PODS_ROOT}/JZLocationConverterSwift
PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier}
SKIP_INSTALL = YES
USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES
framework module JZLocationConverterSwift {
umbrella header "JZLocationConverterSwift-umbrella.h"
export *
module * { export * }
}
CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/JZLocationConverterSwift
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS -suppress-warnings
PODS_BUILD_DIR = ${BUILD_DIR}
PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
PODS_ROOT = ${SRCROOT}
PODS_TARGET_SRCROOT = ${PODS_ROOT}/JZLocationConverterSwift
PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier}
SKIP_INSTALL = YES
USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES
......@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>3.4.3</string>
<string>3.4.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
......
......@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>4.2.0</string>
<string>3.5.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
......
......@@ -203,6 +203,7 @@ if [[ "$CONFIGURATION" == "Debug" ]]; then
install_framework "${BUILT_PRODUCTS_DIR}/ESTabBarController-swift/ESTabBarController_swift.framework"
install_framework "${BUILT_PRODUCTS_DIR}/Hue/Hue.framework"
install_framework "${BUILT_PRODUCTS_DIR}/IQKeyboardManagerSwift/IQKeyboardManagerSwift.framework"
install_framework "${BUILT_PRODUCTS_DIR}/JZLocationConverterSwift/JZLocationConverterSwift.framework"
install_framework "${BUILT_PRODUCTS_DIR}/Kingfisher/Kingfisher.framework"
install_framework "${BUILT_PRODUCTS_DIR}/LGButton/LGButton.framework"
install_framework "${BUILT_PRODUCTS_DIR}/MJRefresh/MJRefresh.framework"
......@@ -223,6 +224,7 @@ if [[ "$CONFIGURATION" == "Release" ]]; then
install_framework "${BUILT_PRODUCTS_DIR}/ESTabBarController-swift/ESTabBarController_swift.framework"
install_framework "${BUILT_PRODUCTS_DIR}/Hue/Hue.framework"
install_framework "${BUILT_PRODUCTS_DIR}/IQKeyboardManagerSwift/IQKeyboardManagerSwift.framework"
install_framework "${BUILT_PRODUCTS_DIR}/JZLocationConverterSwift/JZLocationConverterSwift.framework"
install_framework "${BUILT_PRODUCTS_DIR}/Kingfisher/Kingfisher.framework"
install_framework "${BUILT_PRODUCTS_DIR}/LGButton/LGButton.framework"
install_framework "${BUILT_PRODUCTS_DIR}/MJRefresh/MJRefresh.framework"
......
......@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.1.0</string>
<string>1.0.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment