【问题标题】:Is it possible to have custom reverse geocoding?是否可以进行自定义反向地理编码?
【发布时间】:2015-09-15 14:45:04
【问题描述】:

目前,我正在使用反向地理编码将经度和纬度简单地转换为地点和子地点。

如果我提供了坐标,我是否可以覆盖它并基本上让它返回自定义字符串?有什么想法吗?

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

    }

}

【问题讨论】:

  • 您使用的是CoreLocation、Google Map API 还是其他?你能告诉我更多关于你正在做什么以及你希望它是什么的细节吗?提供代码是最好的。
  • @Ducky 在我的代码中添加了调用反向地理编码。简单地说,我希望能够手动输入坐标并用我自己的字符串覆盖反向地理编码。

标签: ios swift geocoding reverse-geocoding


【解决方案1】:

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

var locale_string

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

...
}

然后,您尚未确定语言环境的默认情况可以按原样接受字符串。 我从 Swift2 编程语言指南第 17 页得到了这个想法。

【讨论】:

    【解决方案2】:

    反向地理编码基本上是一种空间查询。我建议定义一个带有空间边界的地图,为每个边界分配一个位置和子位置的属性。

    使用该地图,您可以针对它运行一组坐标,并为它们分配相同的属性,因为坐标适合某个空间边界。

    【讨论】:

    • 你能再深入一点吗?
    猜你喜欢
    • 2010-11-02
    • 2021-01-26
    • 2018-05-30
    • 1970-01-01
    • 1970-01-01
    • 2013-01-19
    • 2020-02-14
    • 1970-01-01
    相关资源
    最近更新 更多