Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 是否可以进行自定义反向地理编码?_Ios_Swift_Geocoding_Reverse Geocoding - Fatal编程技术网

Ios 是否可以进行自定义反向地理编码?

Ios 是否可以进行自定义反向地理编码?,ios,swift,geocoding,reverse-geocoding,Ios,Swift,Geocoding,Reverse Geocoding,目前,我正在使用反向地理编码来简单地将经度和纬度转换为一个位置和子位置 考虑到我提供的坐标,我是否可以重写它并让它返回自定义字符串?有什么想法吗 func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) { locationManager.stopUpdatingLocation() if(locations.count > 0){

目前,我正在使用反向地理编码来简单地将经度和纬度转换为一个位置和子位置

考虑到我提供的坐标,我是否可以重写它并让它返回自定义字符串?有什么想法吗

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 = "Hello  " + "\(pm.locality)" //+ "\n" + formatter.stringFromDate(date)


                    }

                }
                else
                {
                    self.locationManager.startUpdatingLocation()
                    if let lbutton = self.lbutton {
                        lbutton.text = "Hello  " + "\(pm.subLocality)\n" // + formatter.stringFromDate(date)
                    }

                }
            }

            else {
                println("Problem with the data received from geocoder")
            }
        })

    } else {


        println("Cannot fetch your location")

    }

}

如果您知道名称是什么,可以尝试交换匹配字符串的开关

var locale_string

switch locale_string {
case “name1”:
let displayed_locale_name = “changed_name1”
case “name2”:
let displayed_locale_name = “changed_name2”

...
}
然后,默认情况下,如果您没有识别区域设置,则可以按原样接受字符串。
我是从Swift2编程语言指南第17页得到这个想法的。

反向地理编码基本上是一种空间查询。我建议定义一个具有空间边界的地图,为每个边界指定一个局部性和子局部性属性


使用该地图,您可以对其运行坐标集,并为其指定与坐标适合某个空间边界时相同的属性

您使用的是
CoreLocation
、谷歌地图API还是其他什么?你能给我看一点你正在做的和你希望它是什么的细节吗?提供代码将是最好的。@Ducky在我调用反向地理编码的代码中添加。简单地说,我希望能够手动输入坐标,并用我自己的字符串覆盖反向地理编码。你能更深入一点吗?