gpt4 book ai didi

ios - Mapkit 在 swift 中覆盖问题

转载 作者:行者123 更新时间:2023-11-29 00:51:27 26 4
gpt4 key购买 nike

我在 map 上的 long:39 和 lat:77 位置显示透明圆圈时遇到问题。我还必须一次显示多个圆圈。我是使用 mapkit 的新手,所以要基本。我在这里先向您的帮助表示感谢。

class FirstViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate
{

@IBOutlet weak var mapView: MKMapView!

let locationManager = CLLocationManager()

override func viewDidLoad()
{
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestAlwaysAuthorization()
self.locationManager.startUpdatingLocation()
self.mapView.showsUserLocation = true

}
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
let location = locations.last
let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 1, longitudeDelta: 1))
self.mapView.setRegion(region, animated: true)
self.locationManager.stopUpdatingLocation()//
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError)
{
print("Errors: " + error.localizedDescription)
}

}

最佳答案

class FirstViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestAlwaysAuthorization()
self.locationManager.startUpdatingLocation()
self.mapView.showsUserLocation = true

}

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
let location = locations.last
let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 1, longitudeDelta: 1))
self.mapView.setRegion(region, animated: true)
self.locationManager.stopUpdatingLocation()
// Provide a radius in meters
showCircle(center, radius: <#CLLocationDistance#>)
}

// Radius is measured in meters
func showCircle(coordinate: CLLocationCoordinate2D, radius: CLLocationDistance) {
let circle = MKCircle(centerCoordinate: coordinate, radius: radius)
mapView.addOverlay(circle)
}

}

extension FirstViewController: MKMapViewDelegate {
func mapView(mapView: MKMapView, rendererForOverlay overlay: MKOverlay) -> MKOverlayRenderer {
let circleRenderer = MKCircleRenderer(overlay: circleOverlay)
circleRenderer.fillColor = UIColor.blackColor()
circleRenderer.alpha = 0.1

return circleRenderer
}
}

关于ios - Mapkit 在 swift 中覆盖问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38109195/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com