这是我第一次在这里发帖.我目前陷入困境,试图找出如何在我的地图上添加一个按钮,如果他们在地图上偏离它,将重新显示用户的当前位置.目前我有下面写的代码显示用户的当前位置.
import UIKit
import MapKit
import CoreLocation
class GameViewController: UIViewController,CLLocationManagerDelegate
{
var lastUserLocation: MKUserLocation?
@IBOutlet weak var Map: MKMapView!
let manager = CLLocationManager()
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations[0]
let span:MKCoordinateSpan = MKCoordinateSpanMake(0.00775, 0.00775)
let myLocation: CLLocationCoordinate2D = CLLocationCoordinate2DMake(location.coordinate.latitude,location.coordinate.longitude)
let region: MKCoordinateRegion = MKCoordinateRegionMake(myLocation, span)
Map.setRegion(region, animated: true)
self.Map.showsUserLocation = true
manager.stopUpdatingLocation()
}
override func viewDidLoad() {
super.viewDidLoad()
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyBest
manager.requestAlwaysAuthorization()
manager.startUpdatingLocation()
}
@IBAction func refLocation(_ sender: Any) {
print("click") …Run Code Online (Sandbox Code Playgroud) 我想说它只是从我的阅读和理解来看是服务器端的,但我希望得到一些澄清。谢谢。
asp.net ×1
client-side ×1
code-behind ×1
ios ×1
mapkit ×1
server-side ×1
swift ×1
webforms ×1
xcode ×1