Commit 4ecc9c91 authored by lujunye's avatar lujunye

补充高德转百度坐标方法

parent b65cc90e
......@@ -35,13 +35,13 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo
var manger:CLLocationManager = CLLocationManager()
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
manger.stopUpdatingLocation()
let location = locations.last
lat = location?.coordinate.latitude as! CLLocationDegrees
lng = location?.coordinate.longitude as! CLLocationDegrees
initMapView(lat: lat, lng: lng)
initSearch()
}
manger.stopUpdatingLocation()
let location = locations.last
lat = location?.coordinate.latitude as! CLLocationDegrees
lng = location?.coordinate.longitude as! CLLocationDegrees
initMapView(lat: lat, lng: lng)
initSearch()
}
override func viewDidLoad() {
super.viewDidLoad()
......@@ -56,7 +56,7 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo
}
searchBr.placeholderStr = "从哪儿发货"
searchBr.cornerRadius = 35/2.0
AMapServices.shared().apiKey = "ca417b43e3d031db9c29382cc09a174a"
manger.delegate = self
......@@ -71,7 +71,7 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo
mapView.isZoomEnabled = true
mapView.setCenter(CLLocationCoordinate2D(latitude: lat, longitude: lng), animated: false)
MapBgView.addSubview(mapView!)
let tap = UITapGestureRecognizer(target: self, action: #selector(cancelKeyboard))
mapView.addGestureRecognizer(tap)
......@@ -123,12 +123,12 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo
introView?.addSubview(contentLbl!)
}
titleLbl!.text = response.pois.first?.name
// contentLbl!.text = "contentLbl?.textColor = UIColor.lightGraycontentLbl?.font = UIFont.systemFont(ofSize: 11)contentLbl?.numberOfLines = 0introView?.addSubview(contentLbl!)"
// contentLbl!.text = "contentLbl?.textColor = UIColor.lightGraycontentLbl?.font = UIFont.systemFont(ofSize: 11)contentLbl?.numberOfLines = 0introView?.addSubview(contentLbl!)"
contentLbl!.text = "\(String(describing: response.pois.first!.province!))\(String(describing: response.pois.first!.city!))\(String(describing: response.pois.first!.district!))\( String(describing: response.pois.first!.address!))"
let t = getStrHeight(str: titleLbl!.text!, fontSize: 13)
let c = getStrHeight(str: contentLbl!.text!, fontSize: 11)
let t = getStrHeight(str: titleLbl!.text!, fontSize: 13)
let c = getStrHeight(str: contentLbl!.text!, fontSize: 11)
titleLbl?.snp_updateConstraints({ (make) in
make.top.equalTo(7)
......@@ -169,6 +169,9 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo
make.width.equalTo(w)
make.height.equalTo(t+c+20)
})
}
func getStrHeight(str:String,fontSize:CGFloat) -> CGFloat{
let lbl = UILabel()
......@@ -181,18 +184,18 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo
}
let viewSize = CGSize(width:w , height: CGFloat(MAXFLOAT))
let font = UIFont.systemFont(ofSize: 13)
return (str as NSString).boundingRect(with: viewSize, options: [.usesLineFragmentOrigin], attributes: [NSAttributedString.Key.font:font], context: nil).height
}
//移动后刷新
func mapView(_ mapView: MAMapView!, mapDidMoveByUser wasUserAction: Bool) {
let req = AMapPOIAroundSearchRequest()
//地址
req.location = AMapGeoPoint.location(withLatitude: CGFloat(mapView.centerCoordinate.latitude), longitude: CGFloat(mapView.centerCoordinate.longitude))
req.requireExtension = true
search.aMapPOIAroundSearch(req)
let req = AMapPOIAroundSearchRequest()
//地址
req.location = AMapGeoPoint.location(withLatitude: CGFloat(mapView.centerCoordinate.latitude), longitude: CGFloat(mapView.centerCoordinate.longitude))
req.requireExtension = true
search.aMapPOIAroundSearch(req)
print(mapView.centerCoordinate.latitude,mapView.centerCoordinate.longitude,bd_encrypt(gg_lat: mapView.centerCoordinate.latitude, gg_lon: mapView.centerCoordinate.longitude))
}
var annotation:MAPointAnnotation? = nil
......@@ -224,12 +227,22 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo
annotationView!.image = UIImage(named: "dingzhen")
//设置中心点偏移,使得标注底部中间点成为经纬度对应点
annotationView!.centerOffset = CGPoint(x: 0, y: -15);
return annotationView!
}
return nil
}
//火星坐标系 (GCJ-02)转百度坐标系 (BD-09)算法
func bd_encrypt(gg_lat:Double, gg_lon: Double) -> (bd_lat:Double, bd_lon: Double) {
let x_pi = 3.14159265358979 * 3000.0 / 180.0
let x = gg_lon
let y = gg_lat
let z = sqrt(x * x + y * y) + 0.00002 * sin(y * x_pi)
let theta = atan2(y, x) + 0.000003 * cos(x * x_pi)
let bdlon = z * cos(theta) + 0.0065
let bdlat = z * sin(theta) + 0.006
return (bdlat,bdlon)
}
}
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