Commit b192caa5 authored by lujunye's avatar lujunye

修复返回当前定位bug

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