1
- Я новичок в быстром.
- , пожалуйста, подскажите мне, как отображать
location
на карте, когда пользователь вводит какое-либо место в текстовое поле. с помощью этой строки текстового поля, как отобразить это местоположение на
map
. Это мой кодКак отобразить определенное пользователем местоположениеimport UIKit import CoreLocation import MapKit class DetailViewController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate { var manager:CLLocationManager! var myLocations: [CLLocation] = [] required init(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } override func viewDidLoad() { super.viewDidLoad() //Setup our Location Manager manager = CLLocationManager() manager.delegate = self manager.desiredAccuracy = kCLLocationAccuracyBest manager.requestAlwaysAuthorization() manager.startUpdatingLocation() //Setup our Map View theMap.delegate = self theMap.mapType = MKMapType.Satellite theMap.showsUserLocation = true } func locationManager(manager:CLLocationManager, didUpdateLocations locations:[AnyObject]) { theLabel.text = "\(locations[0])" myLocations.append(locations[0] as CLLocation) let spanX = 0.007 let spanY = 0.007 var newRegion = MKCoordinateRegion(center: theMap.userLocation.coordinate, span: MKCoordinateSpanMake(spanX, spanY)) theMap.setRegion(newRegion, animated: true) if (myLocations.count > 1){ var sourceIndex = myLocations.count - 1 var destinationIndex = myLocations.count - 2 let c1 = myLocations[sourceIndex].coordinate let c2 = myLocations[destinationIndex].coordinate var a = [c1, c2] var polyline = MKPolyline(coordinates: &a, count: a.count) theMap.addOverlay(polyline) } }
благодаря