【发布时间】:2015-06-27 11:53:01
【问题描述】:
我正在将应用从 Xcode 6.2 重建到 6.3.2
在我的 info.plist 中,我使用字符串消息设置 NSLocationWhenInUseUsageDescription,并使用另一个字符串消息设置 Privacy - Location Usage Description。
我打开了功能/地图 我打开了功能/背景模式/位置更新
在构建阶段导入 MapKit 和 CoreLocation 框架
我需要获取单个纬度和经度,因为 Parse 需要它们。
Imas145 回答后更新
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate {
var locationManager = CLLocationManager()
@IBOutlet weak var mapView: MKMapView!
@IBOutlet weak var anotationsCountLabel: UILabel!
@IBOutlet weak var distanceFilterLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.distanceFilter = 100.0 //tot horizontal meters before sending an update on location
mapView.userTrackingMode = .Follow
locationManager.startUpdatingLocation()
}
//MARK: - Helper - CLLocationManagerDelegate
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
if let location = locationManager.location {
var myLatitude = locationManager.location.coordinate.latitude
var myLongitude = locationManager.location.coordinate.longitude
var location = CLLocationCoordinate2D(latitude: myLatitude, longitude: myLongitude)
let span = MKCoordinateSpanMake(0.05, 0.05) //how much to show
let region = MKCoordinateRegionMake(location, span) //how much to show
mapView.setRegion(region, animated: true)
// let anotation = MKPointAnnotation()
// anotation.coordinate = location //was : anotation.setCoordinate(location)
// anotation.title = "you are here"
// anotation.subtitle = "City name"
// mapView.removeAnnotation(anotation)
// mapView.addAnnotation(anotation)
var totalAnotations = mapView.annotations.count
anotationsCountLabel.text = "\(totalAnotations)"
distanceFilterLabel.text = "\(locationManager.distanceFilter)"
println("latitude is: \(myLatitude)")
println("longitude is: \(myLongitude)")
// locationManager.stopUpdatingLocation()
}
}
func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {
println("problem1: error" + error.localizedDescription)
}
}
【问题讨论】:
-
也许@Nils Ziehn 可以帮助我
标签: ios xcode parse-platform