私はiPadのための私の最初の迅速なアプリケーションに取り組んでいます。これまでのところ、基本的なマップビューは、一番下のツールバーのボタンで表示されていました。マップボタンの更新場所
現在、私はこのコードを持っている:
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
var location: CLLocation!
let locationManager = CLLocationManager()
@IBOutlet weak var mapView: MKMapView!
@IBOutlet weak var refresh: UIBarButtonItem!
@IBAction func refresh(sender: AnyObject) {
let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))
self.mapView.setRegion(region, animated: true)
}
override func viewDidLoad() {
super.viewDidLoad()
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
self.mapView.showsUserLocation = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// location delegate methods
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("Error code: " + error.localizedDescription)
}
}
どのように私はこれを行うには、更新ボタンを取得することができますか?私はスウィフト/ Xcodeのに新しいです、私は実際にいくつかの助けが必要です:)
は、あなたがこの機能を使用して場所を更新することができますあなたの
正しく理解しているかどうかはわかりません。なぜコントローラにアクションを加えたり、サービス/マネージャのデータを更新したりしないのですか? – razor118
どうしたらいいですか?私は本当にxcodeに新しいです:(@ razor118私は最新の場所を最新の場所に更新するためにリフレッシュボタンをしたいです – Oscar