Commit b65cc90e authored by lujunye's avatar lujunye

定位缺角

parent 44249884
...@@ -174,7 +174,6 @@ ...@@ -174,7 +174,6 @@
E0707DCE2462479300E039A8 /* SJMapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0707DCD2462479300E039A8 /* SJMapViewController.swift */; }; E0707DCE2462479300E039A8 /* SJMapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0707DCD2462479300E039A8 /* SJMapViewController.swift */; };
E0707DD024624A2F00E039A8 /* AMapSearchKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E0707DCF24624A2F00E039A8 /* AMapSearchKit.framework */; }; E0707DD024624A2F00E039A8 /* AMapSearchKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E0707DCF24624A2F00E039A8 /* AMapSearchKit.framework */; };
E0707DD224624A3700E039A8 /* MAMapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E0707DD124624A3700E039A8 /* MAMapKit.framework */; }; E0707DD224624A3700E039A8 /* MAMapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E0707DD124624A3700E039A8 /* MAMapKit.framework */; };
E0707DD424624A6800E039A8 /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E0707DD324624A6800E039A8 /* CoreLocation.framework */; };
E0707DD624624B5200E039A8 /* AMap.bundle in Resources */ = {isa = PBXBuildFile; fileRef = E0707DD524624B5200E039A8 /* AMap.bundle */; }; E0707DD624624B5200E039A8 /* AMap.bundle in Resources */ = {isa = PBXBuildFile; fileRef = E0707DD524624B5200E039A8 /* AMap.bundle */; };
E07B1E5E24591AA50055BA3C /* KeHuXQViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E07B1E5C24591AA50055BA3C /* KeHuXQViewController.swift */; }; E07B1E5E24591AA50055BA3C /* KeHuXQViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E07B1E5C24591AA50055BA3C /* KeHuXQViewController.swift */; };
E07B1E5F24591AA50055BA3C /* KeHuXQViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = E07B1E5D24591AA50055BA3C /* KeHuXQViewController.xib */; }; E07B1E5F24591AA50055BA3C /* KeHuXQViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = E07B1E5D24591AA50055BA3C /* KeHuXQViewController.xib */; };
...@@ -1297,7 +1296,6 @@ ...@@ -1297,7 +1296,6 @@
E039847C2468F21900DFA56F /* AVFoundation.framework in Frameworks */, E039847C2468F21900DFA56F /* AVFoundation.framework in Frameworks */,
E039847A2468F21100DFA56F /* AudioToolbox.framework in Frameworks */, E039847A2468F21100DFA56F /* AudioToolbox.framework in Frameworks */,
E03984782468F20800DFA56F /* AssetsLibrary.framework in Frameworks */, E03984782468F20800DFA56F /* AssetsLibrary.framework in Frameworks */,
E0707DD424624A6800E039A8 /* CoreLocation.framework in Frameworks */,
F905A7D5246CF57700E3A74D /* Parchment in Frameworks */, F905A7D5246CF57700E3A74D /* Parchment in Frameworks */,
E0707DC52462456C00E039A8 /* libc++.tbd in Frameworks */, E0707DC52462456C00E039A8 /* libc++.tbd in Frameworks */,
F93E32062473C9C200524DFC /* jcore-ios-2.2.5.a in Frameworks */, F93E32062473C9C200524DFC /* jcore-ios-2.2.5.a in Frameworks */,
......
...@@ -15,6 +15,10 @@ notice@gelifood.com ...@@ -15,6 +15,10 @@ notice@gelifood.com
GeliFood GeliFood
81338860geLI 81338860geLI
高德地图
18924107259
81338860geli
微信开发平台 微信开发平台
GELIFOOD123@126.com GELIFOOD123@126.com
81338860geli 81338860geli
......
...@@ -16,20 +16,24 @@ import IQKeyboardManagerSwift ...@@ -16,20 +16,24 @@ import IQKeyboardManagerSwift
protocol SJMapViewControllerDelegate { protocol SJMapViewControllerDelegate {
func SJMapViewControllerSelectArd(adr:String) func SJMapViewControllerSelectArd(adr:String)
} }
class SJMapViewController: UIViewController,AMapLocationManagerDelegate,MAMapViewDelegate,AMapSearchDelegate,UISearchBarDelegate,SearchBarViewDelegate,UITableViewDelegate,UITableViewDataSource{ class SJMapViewController: UIViewController,AMapLocationManagerDelegate,MAMapViewDelegate,AMapSearchDelegate,UISearchBarDelegate,SearchBarViewDelegate,UITableViewDelegate,UITableViewDataSource, CLLocationManagerDelegate{
var delegate:SJMapViewControllerDelegate? var delegate:SJMapViewControllerDelegate?
var mapView: MAMapView! var mapView: MAMapView!
var search: AMapSearchAPI! var search: AMapSearchAPI!
var lat:CLLocationDegrees = 0
var lng:CLLocationDegrees = 0
var manger:CLLocationManager = CLLocationManager()
var adrArr:Array<AMapPOI> = []
var searchV : SearchBarView? = nil var searchV : SearchBarView? = nil
var listView:UITableView? = nil var listView:UITableView? = nil
var lat:CLLocationDegrees = 23.142059
var lng:CLLocationDegrees = 113.240747
var adrArr:Array<AMapPOI> = []
override func viewWillAppear(_ animated: Bool) { override func viewWillAppear(_ animated: Bool) {
self.navigationController?.navigationBar.isHidden = true self.navigationController?.navigationBar.isHidden = true
...@@ -38,12 +42,24 @@ class SJMapViewController: UIViewController,AMapLocationManagerDelegate,MAMapVie ...@@ -38,12 +42,24 @@ class SJMapViewController: UIViewController,AMapLocationManagerDelegate,MAMapVie
IQKeyboardManager.shared.shouldResignOnTouchOutside = true IQKeyboardManager.shared.shouldResignOnTouchOutside = true
} }
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()
initUI()
}
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
AMapServices.shared().apiKey = "ca417b43e3d031db9c29382cc09a174a" AMapServices.shared().apiKey = "ca417b43e3d031db9c29382cc09a174a"
initMapView()
initSearch() manger.delegate = self
initUI() manger.startUpdatingLocation()
} }
//MARK: - 自定义delegate //MARK: - 自定义delegate
...@@ -262,7 +278,7 @@ class SJMapViewController: UIViewController,AMapLocationManagerDelegate,MAMapVie ...@@ -262,7 +278,7 @@ class SJMapViewController: UIViewController,AMapLocationManagerDelegate,MAMapVie
searchBr.delegateL = self searchBr.delegateL = self
} }
func initMapView() { func initMapView(lat:CLLocationDegrees,lng:CLLocationDegrees) {
let btmView = UIView() let btmView = UIView()
self.view.addSubview(btmView) self.view.addSubview(btmView)
btmView.snp.makeConstraints { (make) in btmView.snp.makeConstraints { (make) in
......
...@@ -8,17 +8,41 @@ ...@@ -8,17 +8,41 @@
import UIKit import UIKit
import LGButton import LGButton
import AMapLocationKit
class ToAndFormSelectViewController: BaseViewController { import AMapFoundationKit
import MAMapKit
import AMapSearchKit
import IQKeyboardManagerSwift
class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLocationManagerDelegate, AMapSearchDelegate {
@IBOutlet weak var navBgView: UIView! @IBOutlet weak var navBgView: UIView!
@IBOutlet weak var citySelectBtn: UIButton! @IBOutlet weak var citySelectBtn: UIButton!
@IBAction func backAction(_ sender: Any) {
self.navigationController?.popViewController(animated: true)
}
@IBOutlet weak var phoneTF: UITextField! @IBOutlet weak var phoneTF: UITextField!
@IBOutlet weak var nameTF: UITextField! @IBOutlet weak var nameTF: UITextField!
@IBOutlet weak var addressDetailTF: UITextField! @IBOutlet weak var addressDetailTF: UITextField!
@IBOutlet weak var toFormTitleLbl: UILabel! @IBOutlet weak var toFormTitleLbl: UILabel!
@IBOutlet weak var sureSelectLbl: UILabel! @IBOutlet weak var sureSelectLbl: UILabel!
@IBOutlet weak var MapBgView: UIView! @IBOutlet weak var MapBgView: UIView!
//高德地图
var mapView: MAMapView!
var search: AMapSearchAPI!
var lat:CLLocationDegrees = 0
var lng:CLLocationDegrees = 0
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()
}
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
...@@ -33,11 +57,179 @@ class ToAndFormSelectViewController: BaseViewController { ...@@ -33,11 +57,179 @@ class ToAndFormSelectViewController: BaseViewController {
searchBr.placeholderStr = "从哪儿发货" searchBr.placeholderStr = "从哪儿发货"
searchBr.cornerRadius = 35/2.0 searchBr.cornerRadius = 35/2.0
AMapServices.shared().apiKey = "ca417b43e3d031db9c29382cc09a174a"
manger.delegate = self
manger.startUpdatingLocation()
}
func initMapView(lat:CLLocationDegrees,lng:CLLocationDegrees) {
AMapServices.shared().enableHTTPS = true
mapView = MAMapView(frame:MapBgView.bounds)
mapView.delegate = self
mapView.zoomLevel = 16
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)
}
@objc func cancelKeyboard(){
IQKeyboardManager.shared.resignFirstResponder()
}
func initSearch() {
search = AMapSearchAPI()
search.delegate = self
let request = AMapPOIAroundSearchRequest()
//地址
request.location = AMapGeoPoint.location(withLatitude: CGFloat(mapView.centerCoordinate.latitude), longitude: CGFloat(mapView.centerCoordinate.longitude))
request.requireExtension = true
search.aMapPOIAroundSearch(request)
} }
@IBAction func sureSelectAddressAction(_ sender: LGButton) { @IBAction func sureSelectAddressAction(_ sender: LGButton) {
print("sureSelectAddressAction") print("sureSelectAddressAction")
} }
//MARK: - 高德地图delegate
var introView:UIView?
var titleLbl:UILabel?
var contentLbl:UILabel?
func onPOISearchDone(_ request: AMapPOISearchBaseRequest!, response: AMapPOISearchResponse!) {
if response.count == 0 {
return
}
//解析response获取POI信息,具体解析见 Demo
if introView == nil {
introView = UIView()
MapBgView.addSubview(introView!)
introView?.backgroundColor = UIColor.white
introView?.layer.cornerRadius = 5
introView?.layer.masksToBounds = true
titleLbl = UILabel()
titleLbl?.textColor = UIColor.black
titleLbl?.font = UIFont.systemFont(ofSize: 13)
introView?.addSubview(titleLbl!)
contentLbl = UILabel()
contentLbl?.textColor = UIColor.lightGray
contentLbl?.font = UIFont.systemFont(ofSize: 11)
contentLbl?.numberOfLines = 0
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 = "\(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)
titleLbl?.snp_updateConstraints({ (make) in
make.top.equalTo(7)
make.left.equalTo(10)
make.right.equalTo(-10)
make.height.equalTo(18.5)
})
contentLbl?.sizeToFit()
contentLbl?.snp_updateConstraints({ (make) in
make.top.equalTo(20)
make.left.equalTo(10)
make.right.equalTo(-10)
make.bottom.equalTo(7)
})
let lbl = UILabel()
lbl.text = contentLbl?.text
lbl.font = UIFont.systemFont(ofSize: 11)
lbl.sizeToFit()
let lbl2 = UILabel()
lbl2.text = titleLbl!.text
lbl2.font = UIFont.systemFont(ofSize: 13)
lbl2.sizeToFit()
var w = lbl.bounds.size.width
if w < lbl2.bounds.size.width {
w = lbl2.bounds.size.width
}
if w > fullScreenWidth * 0.75 {
w = fullScreenWidth * 0.75 + 20
}
introView?.snp_updateConstraints({ (make) in
make.centerX.equalTo(MapBgView.snp_centerX)
make.centerY.equalTo(MapBgView.snp_centerY).offset(-(t+c+35))
make.width.equalTo(w)
make.height.equalTo(t+c+20)
})
}
func getStrHeight(str:String,fontSize:CGFloat) -> CGFloat{
let lbl = UILabel()
lbl.text = str
lbl.font = UIFont.systemFont(ofSize: fontSize)
lbl.sizeToFit()
var w = lbl.bounds.size.width
if w > fullScreenWidth * 0.75 {
w = fullScreenWidth * 0.75 + 20
}
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)
}
var annotation:MAPointAnnotation? = nil
func mapViewRegionChanged(_ mapView: MAMapView!) {
let request = AMapReGeocodeSearchRequest()
request.location = AMapGeoPoint.location(withLatitude: CGFloat(mapView.centerCoordinate.latitude), longitude: CGFloat(mapView.centerCoordinate.longitude))
search.aMapReGoecodeSearch(request)
request.requireExtension = true
if annotation == nil
{
let pointAnnotation = MAPointAnnotation()
annotation = pointAnnotation
mapView.addAnnotation(annotation)
}
annotation!.coordinate = CLLocationCoordinate2D(latitude: mapView.centerCoordinate.latitude, longitude: mapView.centerCoordinate.longitude)
}
func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! {
if annotation.isKind(of: MAPointAnnotation.self) {
let pointReuseIndetifier = "pointReuseIndetifier"
var annotationView: MAAnnotationView? = mapView.dequeueReusableAnnotationView(withIdentifier: pointReuseIndetifier)
if annotationView == nil {
annotationView = MAAnnotationView(annotation: annotation, reuseIdentifier: pointReuseIndetifier)
}
annotationView!.image = UIImage(named: "dingzhen")
//设置中心点偏移,使得标注底部中间点成为经纬度对应点
annotationView!.centerOffset = CGPoint(x: 0, y: -15);
return annotationView!
}
return nil
}
} }
...@@ -51,6 +51,9 @@ ...@@ -51,6 +51,9 @@
<state key="normal" title="Button"> <state key="normal" title="Button">
<color key="titleColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> <color key="titleColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</state> </state>
<connections>
<action selector="backAction:" destination="-1" eventType="touchUpInside" id="IxJ-bo-p6P"/>
</connections>
</button> </button>
<button opaque="NO" contentMode="scaleToFill" semanticContentAttribute="forceRightToLeft" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ADf-bf-b5w"> <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="56" y="13.5" width="60" height="18"/>
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="16097" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="16097.2" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/> <device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies> <dependencies>
<deployment identifier="iOS"/> <deployment identifier="iOS"/>
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="16097" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="16097.2" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/> <device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies> <dependencies>
<deployment identifier="iOS"/> <deployment identifier="iOS"/>
......
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