【发布时间】:2015-10-14 22:47:37
【问题描述】:
所以,我目前的问题如下。
我想基本上使用我当前的视图控制器,但在应用程序中的其他位置更改位置设置,并让数据通过带有更新的位置信息的视图控制器。
我会详细说明。我目前正在使用以下代码进行反向地理编码,并获取用户位置。
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
locationManager.stopUpdatingLocation()
if(locations.count > 0){
let location = locations[0] as! CLLocation
// println(location.coordinate)
if let currentLocatino = currLocation {
if CLLocation(latitude: currentLocatino.latitude, longitude: currentLocatino.longitude).distanceFromLocation(location) > 500 {
currLocation = location.coordinate
self.skip = 0
self.loadObjects()
}
}
else {
currLocation = location.coordinate
self.skip = 0
self.loadObjects()
}
CLGeocoder().reverseGeocodeLocation(CLLocation(latitude: currLocation!.latitude, longitude: currLocation!.longitude), completionHandler: {(placemarks, error) -> Void in
if error != nil {
println("Reverse geocoder failed with error" + error.localizedDescription)
return
}
if placemarks.count > 0 {
let date = NSDate()
let formatter = NSDateFormatter()
formatter.dateStyle = .MediumStyle
formatter.stringFromDate(date)
let pm = placemarks[0] as! CLPlacemark
var testifempty = "\(pm.subLocality)"
if testifempty == "nil"
{
self.locationManager.startUpdatingLocation()
if let lbutton = self.lbutton{
lbutton.text = "Hey " + "\(pm.locality)" //+ "\n" + formatter.stringFromDate(date)
}
}
else
{
self.locationManager.startUpdatingLocation()
if let lbutton = self.lbutton {
lbutton.text = "Hey " + "\(pm.subLocality)\n" // + formatter.stringFromDate(date)
}
}
}
else {
println("Problem with the data received from geocoder")
}
})
} else {
println("Cannot fetch your location")
}
}
我想要的是,它本质上是通过一个新位置并设置一个布尔值,这样如果该布尔值设置为 false,新位置信息就会通过应用程序传递。
我正在考虑在主视图控制器上使用开关,并在辅助视图控制器上更改位置。
很抱歉,如果这是一篇很长的帖子,但我觉得我正处于弄清楚如何做到这一点的边缘,但我需要确保我朝着正确的方向前进。
也许我可以使用 mapkit 并使用注释?
【问题讨论】:
标签: ios swift uitableview core-location