标签: clgeocoder

iOS - MKMapKit,显示注释中用户位置的地址

默认情况下,我们可以在地图视图中显示用户的位置.点击注释引脚时,它将显示"当前位置".但我想将用户的地址显示为街道,城市和国家.我怎么能用CLGeoCoder课来做呢?

mapkit ios clgeocoder

2
推荐指数
1
解决办法
1722
查看次数

在美国以外的地区,administrativeArea、subAdministrativeArea 等的名称是什么?

我正在开发一个具有地理意识的高分服务器,并且希望能够列出诸如“Dutchess 县第一名”或“纽约州第三名”之类的分数。我可以对用户的位置进行反向地理编码并获得一个列出管理区域等的地标。

对于上述示例,iOS 和 Google 使用的反向地理编码器将返回“Dutchess”和“New York”,因此我需要为美国提供“County”和“State”。

但是,游戏是全球性的,所以我需要知道其他英语国家的每个地理组织级别的名称。

因此,在美国,Google / iOS 地标级别将描述如下:

行政区 = "州"

SubAdministrativeArea =“县”(或路易斯安那州的“教区”)

Locality =“城市”或“城镇”

Sublocality =(我称之为“邻里”)

PostalCode = "邮政编码"

所有这些级别在其他英语国家叫什么?(加拿大、英国、澳大利亚、新西兰、新加坡等)。如果有列出所有这些的资源,我很想知道。我想我可能只是不知道在网上搜索什么。

google-maps reverse-geocoding ios clgeocoder

1
推荐指数
1
解决办法
1981
查看次数

如何从CLGeocoder解析地标只显示城市

我使用以下代码从CLGeocoder接收地标,我想在同一个viewcontroller上只显示另一个textview中的城市.我如何从这个阵列中解析出这座城市?它不是NSDictionary或任何东西,所以我不知道该怎么做.

CLGeocoder *geocoder = [[CLGeocoder alloc] init];

[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
    NSLog(@"reverseGeocodeLocation:completionHandler: Completion Handler called!");
    if (error){
        NSLog(@"Geocode failed with error: %@", error);
        return;
    }
    NSLog(@"Received placemarks: %@", placemarks);
}];
Run Code Online (Sandbox Code Playgroud)

我给定地标的日志如下:

<__ NSArrayM 0x1a0b3810>(937-961 Sunnyvale Saratoga Rd,937-961 Sunnyvale Saratoga Rd,Sunnyvale,CA 94087,United States @ + + 37.35984860,-122.03235910> +/- 100.00m)

要么

<__ NSArrayM 0x19576ac0>(5600 Van Nuys Blvd,5600 Van Nuys Blvd,Van Nuys,CA 91401-4602,United States @ <+ 34.17257000,-118.44794450> +/- 100.00m,region(identifier <+ 34.17257001,-118.44794464> radius 57.64)<+ 34.17257001,-118.44794464>半径57.64m)

我如何才能将Sunnyvale或Van Nuys的部分显示为字符串?

xcode parsing core-location mkmapview clgeocoder

1
推荐指数
1
解决办法
1273
查看次数

使用reverseGeocodeLocation设置地址字符串:并从方法返回

我尝试将起点和终点本地化为地址字符串,以便我可以将其存储到NSUserDefaults.问题是该方法继续执行并且不设置我的变量.

NSLog(@"Begin");

__block NSString *returnAddress = @"";

[self.geoCoder reverseGeocodeLocation:self.locManager.location completionHandler:^(NSArray *placemarks, NSError *error) {
    if(error){
        NSLog(@"%@", [error localizedDescription]);
    }

    CLPlacemark *placemark = [placemarks lastObject];

    startAddressString = [NSString stringWithFormat:@"%@ %@\n%@ %@\n%@\n%@",
                          placemark.subThoroughfare, placemark.thoroughfare,
                          placemark.postalCode, placemark.locality,
                          placemark.administrativeArea,
                          placemark.country];
    returnAddress = startAddressString;

    //[self.view setUserInteractionEnabled:YES];
}];
NSLog(returnAddress);

NSLog(@"Einde");
Run Code Online (Sandbox Code Playgroud)

这是我的应用程序调试器显示的内容:

启动
einde

例如,我的位置地址是:"Mainstreet 32​​,CITY".然后我想看到的是以下内容:

启动
Mainstreet 32​​,CITY
Einde

问题是我的代码不等待我CLGeocoder完成,所以我的变量returnAddress在返回时没有设置,并且它是空的.

有谁知道如何解决这个问题?

cocoa-touch objective-c ios clgeocoder completionhandler

1
推荐指数
1
解决办法
1万
查看次数

Swift:使用异步方法获取值

我正在为这种情况寻找一两个好的习语:

我想使用异步反向地理定位调用将 CLLocationCooperative2D 转换为 CLPlacemark,作为一系列其他操作的一部分。

转换步骤在很大程度上是一个“实用”步骤,因此在处理程序中放入大量代码来执行“其他操作”感觉结构很差。

我可以将结果存储在类变量中,但我需要知道异步步骤何时完成,这意味着某种事件触发或主线程排队超时或其他什么,这也看起来很尴尬。

有标准方法吗?将代码放入处理程序中是否很常见?

谢谢!

这是我的上下文的具体代码,FWIW。

func getPlaceFromCoordinate(coordinate: CLLocationCoordinate2D) -> CLPlacemark? {

    var loc = CLLocation(
        latitude: coordinate.latitude,
        longitude: coordinate.longitude
    )

    var mightBeAPlace: CLPlacemark? = nil

    CLGeocoder().reverseGeocodeLocation(loc, completionHandler: {(placemarks, error) -> Void in
        if(error != nil) {
            println("Reverse geocoding error.")
        }
        else if (placemarks.count == 0) {
            println("no placemarks")
        }
        else { // if (placemarks.count > 0)
            println("we have placemarks")
            mightBeAPlace = CLPlacemark(placemark: placemarks[0] as! CLPlacemark)
            println("Inside closure place: \(mightBeAPlace?.locality)")
            lastUserSelectedPlace = mightBeAPlace // This stores …
Run Code Online (Sandbox Code Playgroud)

asynchronous reverse-geocoding ios clgeocoder swift

1
推荐指数
1
解决办法
1525
查看次数

CLGeocodeCompletionHandler ios swift3

有没有人知道swift3上的任何变化?如何修复以下代码我使用geococdeAddressString

class func getMapByAddress(_ locationMap:MKMapView?, address:String?, title: String?, subtitle: String?)
{
            let geocoder = CLGeocoder()
            geocoder.geocodeAddressString(address!, completionHandler: {(placemarks: [CLPlacemark]?, error: NSError?) -> Void in
                if let validPlacemark = placemarks?[0]{
                    print(validPlacemark.location?.coordinate)

                    let span = MKCoordinateSpanMake(0.05, 0.05)
                    let region = MKCoordinateRegion(center: (validPlacemark.location?.coordinate)!, span: span)
                    locationMap?.setRegion(region, animated: true)

                    let annotation = MKPointAnnotation()
                    annotation.coordinate = (validPlacemark.location?.coordinate)!
                    annotation.title = title
                    annotation.subtitle = subtitle
                    locationMap?.addAnnotation(annotation)
                }

            } as! CLGeocodeCompletionHandler)
}
Run Code Online (Sandbox Code Playgroud)

这一行出错......只是在此行崩溃,as! CLGeocodeCompletionHandler) 没有显示错误<private>

clgeocoder swift3

0
推荐指数
1
解决办法
802
查看次数

为什么在闭包完成相同的函数之前执行延迟块

我在Swift 2.0中编写了以下函数来添加一个地图注释,用于CLGeocoder()解析给定坐标的位置名称.我使用一个defer块来获取已解析的位置名称,但是,在闭包完成之前,延迟块似乎已完成.为什么?

以下是我的代码:

func addAnnotation(gestureRecognizer: UIGestureRecognizer) {
    var locationNameStr = ""
    defer {
        let newPin = Pin(dictionary: locationDictionary, context: sharedContext)
        newPin.name = locationNameStr

        do {
            //persist the new pin to core data
            try sharedContext.save()
            showPinOnMap(newPin)
        } catch let error as NSError {
            print("error saving the new pin in context")
        }
    }

    // use CLGeocoder to resolve the location name as title of the annotation
    CLGeocoder().reverseGeocodeLocation(CLLocation(latitude: newCoordinate.latitude, longitude: newCoordinate.longitude), completionHandler: {(placemarks, error) -> Void in

        if error …
Run Code Online (Sandbox Code Playgroud)

asynchronous ios deferred clgeocoder swift

-3
推荐指数
2
解决办法
3255
查看次数