gpt4 book ai didi

ios - 位置管理器功能未被调用

转载 作者:行者123 更新时间:2023-11-30 14:04:16 25 4
gpt4 key购买 nike

import UIKit
import MapKit
import CoreLocation

class StartViewController: UIViewController, CLLocationManagerDelegate
{

var latitude,longitude: Double?
var obLocatinManager: CLLocationManager?
@IBOutlet var objMapView: MKMapView?
@IBOutlet var standard: UIButton?
@IBOutlet var satellite: UIButton?
@IBOutlet var hybrid: UIButton?
@IBOutlet var mapView: UILabel?






override func viewDidLoad() {
super.viewDidLoad()

edgesForExtendedLayout = UIRectEdge.None
let swipeRight = UISwipeGestureRecognizer(target: self, action: "respondToSwipeGesture:")
swipeRight.direction = UISwipeGestureRecognizerDirection.Left
self.view.addGestureRecognizer(swipeRight)

}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

func loadUserLocation() -> Void
{

obLocatinManager?.delegate = self;
obLocatinManager?.distanceFilter = kCLDistanceFilterNone
obLocatinManager?.desiredAccuracy = kCLLocationAccuracyHundredMeters


obLocatinManager?.requestWhenInUseAuthorization()

obLocatinManager?.startUpdatingLocation()
}

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {

let newlocaton = locations[1] as! CLLocation
self.latitude = newlocaton.coordinate.latitude
self.longitude = newlocaton.coordinate.longitude
obLocatinManager?.stopUpdatingLocation()
self.loadMapView()

}
func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {
obLocatinManager?.stopUpdatingLocation()
}

func loadMapView() -> Void
{
var latDelta:CLLocationDegrees = 0.2
var longDelta:CLLocationDegrees = 0.2
var objCoor2D: CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: self.latitude!, longitude: self.longitude!)
var objCoorSpan: MKCoordinateSpan = MKCoordinateSpanMake(latDelta, longDelta)
var region: MKCoordinateRegion = MKCoordinateRegionMake(objCoor2D, objCoorSpan)
self.objMapView!.setRegion(region, animated: false)

}

@IBAction func didtapStandard(sender: UIButton)
{
self.standard?.backgroundColor = UIColor.greenColor()
self.satellite?.backgroundColor = UIColor.clearColor()
self.hybrid?.backgroundColor = UIColor.clearColor()
self.objMapView?.mapType = MKMapType.Standard
self.loadUserLocation()
println(self.longitude)
println(self.latitude)
}
@IBAction func didtapSatellite(sender: UIButton)
{
self.satellite?.backgroundColor = UIColor.greenColor()
self.standard?.backgroundColor = UIColor.clearColor()
self.hybrid?.backgroundColor = UIColor.clearColor()
self.objMapView?.mapType = MKMapType.Satellite
self.loadUserLocation()
println(self.longitude)
println(self.latitude)
}
@IBAction func didtapHybrid(sender: UIButton)
{
self.hybrid?.backgroundColor = UIColor.greenColor()
self.satellite?.backgroundColor = UIColor.clearColor()
self.standard?.backgroundColor = UIColor.clearColor()
self.objMapView?.mapType = MKMapType.Hybrid
self.loadUserLocation()
println(self.longitude)
println(self.latitude)
}

我尝试使用 IOS 中的 map 套件获取位置,但(位置管理器)这些函数没有被调用

最佳答案

您永远不会在任何地方初始化 CLLocationManager 对象。将以下代码放入View Did Appear中

obLocatinManager = CLLocationManager()

当您使用模拟器时,您可以通过此菜单调用位置更改。我认为我需要首先进行一些更改,以尝试在模拟器中捕获位置更改委托(delegate)。

enter image description here

关于ios - 位置管理器功能未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32606832/

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