飞道的博客

Swift5.2 Control IOSMap(苹果地图)

176人阅读  评论(0)

一直觉得自己写的不是技术,而是情怀,一个个的教程是自己这一路走来的痕迹。靠专业技能的成功是最具可复制性的,希望我的这条路能让你们少走弯路,希望我能帮你们抹去知识的蒙尘,希望我能帮你们理清知识的脉络,希望未来技术之巅上有你们也有我。

地图搜索热点

效果

使用


SearchMapView
import CoreLocation
import MapKit
//地图
let mapView = SearchMapView()
view.addSubview(mapView)
mapView.frame = view.bounds
//获取当前定位地址
mapView.locationCallBlock = {
    (_ location:CLLocationCoordinate2D) -> () in
  print("latitude = \(location.latitude)")
  print("longitude = \(location.longitude)")
}
//获取点击回来的地址
mapView.messageCallBlock = {
    (_ message:MKMapItem) -> () in
  print("name = \(String(describing: message.name))")
  print("name = \(message.placemark.coordinate)")
}

地图定位当前当前位置


import CoreLocation
import MapKit

let mapView = IOSMapView()
view.addSubview(mapView)
mapView.frame = view.bounds
//地图获取当前位置
mapView.locationCallBlock = {
   (_ location:CLLocationCoordinate2D) -> () in
  print("location.latitude = \(location.latitude)")
  print("location.longitude = \(location.longitude)")
}

定位类定位

//获取经纬度,地址
 LocationManager.shareManager.creatLocationManager().startLocation {
    (location, address, error) in
   print("经度 \(location?.coordinate.longitude ?? 0.0)")
   print("纬度 \(location?.coordinate.latitude ?? 0.0)")
   print("地址\(address ?? "")")
   print("error\(error ?? "没有错误")")
   
 }

 //地理编码:通过地址获取经纬度
 LocationManager.shareManager.geocoderClick(address: "广东省佛山市顺德区广珠公路") {
    (location) in
//          print("经度,纬度\(location?.coordinate.latitude, location?.coordinate.longitude)")
     print("经度,纬度\(String(describing: location?.coordinate))")
 }

 //反地理编码:通过经纬度获取地址
 LocationManager.shareManager.reverceGeocoderClick(latitude: 22.755849000000001, longitude: 113.275504) {
    (adress) in
   print("adress = \(String(describing: adress))")
 }

 //CLLocationCoordinate2D 转 CLLocation
 var curAddressCoordinate = CLLocationCoordinate2D()
 curAddressCoordinate.latitude = 113.150783619017
 curAddressCoordinate.longitude = 22.8123897593681
 let cllocation_0 = LocationManager.shareManager.constructWithCLLocation(coordinate: curAddressCoordinate)
 print("cllocation = \(cllocation_0)")

 //CLLocation 转 CLLocationCoordinate2D
 let cllocation_1 = CLLocation(latitude: 113.150783619017, longitude: 22.8123897593681)
 let location = LocationManager.shareManager.constructWithCLLocationCoordinate2D(loaction: cllocation_1)
 print("location = \(location)")

转载:https://blog.csdn.net/weixin_38716347/article/details/115643763
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场