PublishAddAddressController.swift 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // PublishAddAddressController.swift
  3. // RainbowPlanet
  4. //
  5. // Created by Christopher on 2019/6/17.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. //
  8. import UIKit
  9. class PublishAddAddressController: BaseViewController {
  10. override func didReceiveMemoryWarning() {
  11. super.didReceiveMemoryWarning()
  12. }
  13. deinit {
  14. NXLLog("deinit")
  15. }
  16. typealias SelectLocationClosure = (_ address:String) -> Void
  17. var selectLocationClosure : SelectLocationClosure?
  18. var locationAddress: String?
  19. /// 纬度
  20. var latitude : String = LocationModel.shared().object()?.latitude ?? "34.20840377740726"
  21. /// 经度
  22. var longitude : String = LocationModel.shared().object()?.longitude ?? "108.96265686107972"
  23. /// poiList
  24. var poiList: Array<SwiftLocationPOIModel> = LocationModel.shared().object()?.poiList ?? []
  25. override func viewDidLoad() {
  26. super.viewDidLoad()
  27. setupViews()
  28. setupLayouts()
  29. BaiduMapManager.shared.startLocation()
  30. BaiduMapManager.shared.locationSuccessBlock = {
  31. [weak self] in
  32. self?.poiList = LocationModel.shared().object()?.poiList ?? []
  33. self?.addressPOIView.poiList = self?.poiList
  34. }
  35. BaiduMapManager.shared.locationFalseBlock = { SwiftProgressHUD.shared().showText("定位失败")
  36. }
  37. }
  38. override func viewWillAppear(_ animated: Bool) {
  39. navigationController?.interactivePopGestureRecognizer?.isEnabled = false
  40. }
  41. override func viewWillDisappear(_ animated: Bool) {
  42. navigationController?.interactivePopGestureRecognizer?.isEnabled = true
  43. }
  44. override func setupViews() {
  45. navigationBar.leftButton.isHidden = true
  46. navigationBar.addSubview(navigationBarView)
  47. view.addSubview(addressPOIView)
  48. view.insertSubview(navigationBar, aboveSubview: addressPOIView)
  49. addressPOIView.locationAddress = locationAddress
  50. addressPOIView.longitude = longitude
  51. addressPOIView.latitude = latitude
  52. }
  53. override func setupLayouts() {
  54. navigationBarView.snp.makeConstraints { (make) in
  55. make.top.equalTo(kSafeStatusBarHeight)
  56. make.bottom.left.right.equalToSuperview()
  57. }
  58. addressPOIView.snp.makeConstraints { (make) in
  59. make.top.equalTo(navigationBar.snp.bottom)
  60. make.left.right.bottom.equalToSuperview()
  61. }
  62. }
  63. private lazy var navigationBarView: SearchAddrNavigationbarView = {
  64. let navigationBarView = SearchAddrNavigationbarView()
  65. navigationBarView.cancelBlock = {
  66. [weak self] in
  67. self?.navigationController?.popViewController(animated: true)
  68. }
  69. navigationBarView.searchBlock = {
  70. [weak self] keyword in
  71. self?.addressPOIView.searchPOI(keyword)
  72. }
  73. return navigationBarView
  74. }()
  75. private lazy var addressPOIView: PublishAddressPOIView = {
  76. let addressPOIView = PublishAddressPOIView()
  77. addressPOIView.didSelectBlock = { [weak self] (latitude:String,longitude:String,address:String) in
  78. if let selectLocationClosure = self?.selectLocationClosure {
  79. selectLocationClosure(address)
  80. self?.navigationController?.popViewController(animated: true)
  81. }
  82. }
  83. return addressPOIView
  84. }()
  85. }