2016-03-25 18 views
1

私は地図上のユーザーの正確な位置を取得しようとしていますが、正確な場所ではなく都市名のみを受け取りました。ここにコードがあります。地図上にユーザーの所在地を取得できないxcode 7.1

import UIKit 
import MapKit 
import CoreLocation 

class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate 
{ 
@IBOutlet weak var mapView: MKMapView! 

let locationManager = CLLocationManager() 

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. 
} 


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

    let location = locations.last! as CLLocation 

    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) 
} 

func locationManager(manager: CLLocationManager, didFailWithError error: NSError) 
{ 
    print("Error: " + error.localizedDescription) 
} 

} 

NSLocationWhenInUseUsageDescription plistファイルを追加します。 助けてください。ありがとうございました

答えて

0

あなたがシミュレータでこれを探しているならば。その後、この手順に従ってズームマップを表示します。地図の通りを見ることができるようにする

オプション/ Altキーを押す - > 2ラウンドが表示されます。 ズームイン/アウトでピンチイン/アウト

+0

はい、現在の場所には円が表示されますが、現在の場所には表示されません。国/都市名を指すだけです。 – fmas

+0

私はあなたがこのhttp://stackoverflow.com/questions/9056451/draw-a-circle-of-1000m-radius-around-users-location-in-mkmapviewを探していることを願っています。 –

関連する問題