IMShowLocationViewController.swift 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //
  2. // IMShowLocationViewController.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2020/6/18.
  6. // Copyright © 2020 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. class IMShowLocationViewController: UIViewController {
  10. private var mapView: BMKMapView!
  11. private var annotation: BMKPointAnnotation!
  12. var address: String?
  13. var addressDetail: String?
  14. var latitude: Double?
  15. var longitude: Double?
  16. override func viewDidLoad() {
  17. super.viewDidLoad()
  18. self.title = address
  19. mapView = BMKMapView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH ,height: SCREEN_HEIGHT))
  20. mapView.zoomLevel = 17
  21. mapView.showMapPoi = true
  22. mapView.showIndoorMapPoi = true
  23. self.view.addSubview(mapView)
  24. guard let lat = latitude, let lo = longitude else {
  25. self.showError(title: "没有传入正确的地址参数!")
  26. return
  27. }
  28. //更新地图位置
  29. let user = BMKUserLocation()
  30. let loc = CLLocation(latitude: lat, longitude: lo)
  31. user.location = loc
  32. mapView.updateLocationData(user)
  33. mapView.centerCoordinate = CLLocationCoordinate2D(latitude: loc.coordinate.latitude, longitude: loc.coordinate.longitude)
  34. //设置位置点
  35. annotation = BMKPointAnnotation()
  36. annotation.coordinate = loc.coordinate
  37. annotation.title = address
  38. annotation.subtitle = addressDetail
  39. mapView.addAnnotation(annotation)
  40. }
  41. }