0
Swift 2.1でユーザーの場所をズームインする方法を理解しようとしています。私はインターネットの世界を調査しましたが、解決策を見つけることができませんでした。私はこれを開始助けるためRenier Melianに感謝が、それは場所の許可を要求していないと、エラーメッセージSwiftユーザーの場所をズームインする
を与えるimport Foundation
import MapKit
import CoreLocation
class SocialViewController : UIViewController {
@IBOutlet weak var mapView: MKMapView!
var locationManager = CLLocationManager()
override func viewDidLoad() {
self.locationManager.requestWhenInUseAuthorization()
super.viewDidLoad()
self.mapView.showsUserLocation = true
self.mapView.userTrackingMode = .Follow
self.mapView.delegate = self
self.locationManager.startUpdatingLocation()
self.locationManager.delegate = self
}
}
extension SocialViewController : MKMapViewDelegate{
//Adjusting the zoom
func mapView(_ mapView: MKMapView, didUpdate userLocation: MKUserLocation) {
var region = MKCoordinateRegion()
region.span = MKCoordinateSpanMake(0.7, 0.7); //Zoom distance
let coordinate = CLLocationCoordinate2D(latitude: userLocation.coordinate.latitude, longitude: userLocation.coordinate.longitude)
region.center = coordinate
mapView.setRegion(region, animated: true)
}
func mapViewWillStartLocatingUser(_ mapView: MKMapView) {
debugPrint("startLocating")
}
func mapViewDidStopLocatingUser(_ mapView: MKMapView) {
debugPrint("stopLocating")
}
}
extension SocialViewController: CLLocationManagerDelegate
{
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
debugPrint("received Location")
}
}
に役立つ「MKMapViewDelgateを?」' – salipshitz
再び私の答えをチェックし@salipshitz、あなたが作っ –
編集されました'MKMapViewDelegate'の代わりに' MKMapViewDelgate'を書いたときのタイプミスです – salipshitz