Commit b192caa5 authored by lujunye's avatar lujunye

修复返回当前定位bug

parent 451c4336
...@@ -30,10 +30,11 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo ...@@ -30,10 +30,11 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo
var detailAdrStr = "" var detailAdrStr = ""
@objc func backToCurrentLoc(_ sender: Any) { @objc func backToCurrentLoc(_ sender: Any) {
print("返回当前位置")
cityName = tempCityName as NSString cityName = tempCityName as NSString
lat = tempLat lat = tempLat
lng = tempLng lng = tempLng
print("返回当前位置",lat,lng)
mapView.centerCoordinate = CLLocationCoordinate2D(latitude: lat, longitude: lng) mapView.centerCoordinate = CLLocationCoordinate2D(latitude: lat, longitude: lng)
searchList.isHidden = true searchList.isHidden = true
closeBtn.isHidden = true closeBtn.isHidden = true
...@@ -252,7 +253,7 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo ...@@ -252,7 +253,7 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo
let searchBr = SearchBarView.init() let searchBr = SearchBarView.init()
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
navBgView.addSubview(searchBr) navBgView.addSubview(searchBr)
searchBr.snp.makeConstraints { (make) in searchBr.snp.makeConstraints { (make) in
make.left.equalTo(citySelectBtn.snp_right).offset(5) make.left.equalTo(citySelectBtn.snp_right).offset(5)
...@@ -277,12 +278,12 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo ...@@ -277,12 +278,12 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo
AMapServices.shared().apiKey = "ca417b43e3d031db9c29382cc09a174a" AMapServices.shared().apiKey = "ca417b43e3d031db9c29382cc09a174a"
if lat == 0 && lng == 0 {
manger.delegate = self manger.delegate = self
manger.requestAlwaysAuthorization() manger.requestAlwaysAuthorization()
manger.requestWhenInUseAuthorization() manger.requestWhenInUseAuthorization()
manger.startUpdatingLocation() manger.startUpdatingLocation()
}
initMapView() initMapView()
initSearch() initSearch()
...@@ -314,17 +315,15 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo ...@@ -314,17 +315,15 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
manger.stopUpdatingLocation() manger.stopUpdatingLocation()
let location = locations.last let location = locations.last
lat = location?.coordinate.latitude as! CLLocationDegrees if lat == 0 && lng == 0 {
lng = location?.coordinate.longitude as! CLLocationDegrees lat = location?.coordinate.latitude as! CLLocationDegrees
lng = location?.coordinate.longitude as! CLLocationDegrees
tempLat = lat mapView.centerCoordinate = CLLocationCoordinate2DMake((lat),(lng))
tempLng = lng }
tempLat = location?.coordinate.latitude as! CLLocationDegrees
mapView.centerCoordinate = CLLocationCoordinate2DMake((lat),(lng)) tempLng = location?.coordinate.longitude as! CLLocationDegrees
} }
func setMapCenter(lat:CLLocationDegrees,lng:CLLocationDegrees) { func setMapCenter(lat:CLLocationDegrees,lng:CLLocationDegrees) {
mapView.setCenter(CLLocationCoordinate2D(latitude: lat, longitude: lng), animated: false) mapView.setCenter(CLLocationCoordinate2D(latitude: lat, longitude: lng), animated: false)
} }
...@@ -544,7 +543,7 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo ...@@ -544,7 +543,7 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo
"name":titleLbl!.text, "name":titleLbl!.text,
"city_id":city_id "city_id":city_id
] as [String : Any] ] as [String : Any]
adrDataModel = cityListDataModel(JSON: d) adrDataModel = cityListDataModel(JSON: d)
} }
isHistory = false isHistory = false
......
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