标签: clgeocoder

发出前向地理编码多个地址

我正在连接到一个基本上返回XML的远程Web服务.然后我将该XML解析为Property对象(想想真实的状态)

但现在,Web服务仅返回每个属性的邮政编码.它没有提供我需要在地图中放置注释的坐标.我能够为邮政编码提供地址代码.但是,我的问题是它不允许我做多个请求

这是我的代码

- (void)processProperties:(Property *)property {

    [geocoder geocodeAddressString:property.postalCode
                 completionHandler:^(NSArray* placemarks, NSError* error){
                     placemark = [placemarks lastObject];
                     for (CLPlacemark* aPlacemark in placemarks)
                     {
                         [sublet setLatitude:aPlacemark.location.coordinate.latitude];
                         [sublet setLongitude:aPlacemark.location.coordinate.longitude];  
                     }
                 }];
}


- (void)addAnnotations:(NSArray *)objects {
    CLLocationDegrees lat;
    CLLocationDegrees longitude;
    CLLocationCoordinate2D mCoords;
    NSString *fullAddress;

    // Add the annotations found nearby
    for (Property *property in objects) {

        [self processProperties:property];
        lat = property.latitude;
        longitude = property.longitude;

        fullAddress = [NSString stringWithFormat:@"%@ %@ %@", property.houseNumber, @" ", property.streetName];
        [self createAnnotationWithCoords:mCoords :fullAddress :[NSString stringWithFormat:@"$%.2f", property.rent]];
    } …
Run Code Online (Sandbox Code Playgroud)

objective-c geocode ios5 clgeocoder

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

将MKMapView更新为从CLGeocoder返回的CLPlacemark

我希望能够通过允许用户在UIAlertView中键入地址或位置来更新MKMapView上显示的区域.我目前有:

        if (geocoder.geocoding)
            [geocoder cancelGeocode];

        [geocoder geocodeAddressString:[[alertView textFieldAtIndex:0] text] completionHandler:^(NSArray *placemarks, NSError *error) {
            if (!error) {
                NSLog(@"Found a location");
            } else {
                NSLog(@"Error in geocoding");
            }

            NSLog(@"Num found: %d", [placemarks count]);

            CLPlacemark *placemark = [placemarks objectAtIndex:0];
            MKCoordinateRegion region;
            region.center.latitude = placemark.region.center.latitude;
            region.center.longitude = placemark.region.center.longitude;
            MKCoordinateSpan span;
            double radius = placemark.region.radius / 1000;

            NSLog(@"Radius is %f", radius);
            span.latitudeDelta = radius / 112.0;
            //span.longitudeDelta = ??? 

            region.span = span;

            NSLog(@"Region is %f %f %f", region.center.latitude, region.center.longitude, span.latitudeDelta);

            [mapView setRegion:region animated:YES];
        }]; …
Run Code Online (Sandbox Code Playgroud)

mkcoordinateregion mkmapview cllocation ios clgeocoder

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

iOS5 CLGeocoder

我正在为IOS5开发一款iPhone应用程序.我目前正在使用位于CoreLocation框架内的CLGeocoder类.在地理编码发生或同时发生后,我无法弄清楚最后是否调用了完成处理程序块.

我只知道完成处理程序块是在主线程上运行的.有没有人知道完成处理程序块是在地理编码完成时运行还是在地理编码器在另一个线程上执行时完成手头任务的代码?

iphone ios objective-c-blocks ios5 clgeocoder

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

将MKMapView缩放级别设置为某个位置

我希望设置MKMapView的缩放级别(OR设置区域),以便我可以显示一个位置.用一个例子来阐述我的背景.我有一个位置(CLLocation*),我使用CLGeocoder(反向地理编码)找到了该地点.现在,说地方是'库比蒂诺,加州'地区.如何在MKMapView中找到完全包含Cupertino的区域?

谢谢.

mkmapview ios clgeocoder

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

iOS-没有互联网连接的CLGeocoder

CLGeocoder用来在地图上定位地址,并计算用户与整个地址的距离。

这是使用的部分代码CLGeocoder

CLGeocoder *geocoder = [[CLGeocoder alloc] init];
__block float distance;
__block CLLocation *location;
[geocoder geocodeAddressString:adresseFinal completionHandler:^(NSArray *placemarks, NSError *error) {
    if ([placemarks count] > 0) {
        CLPlacemark *placemark = [placemarks objectAtIndex:0];
        location = placemark.location;
        CLLocationCoordinate2D coordinate = location.coordinate;
        distance = [userLocation distanceFromLocation:location];
        [distanceArray addObject:[NSString stringWithFormat:@"%f", distance]];
        MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
        point.coordinate = coordinate;
        point.title = tableNoms[i];
        NSMutableArray *coords = [[NSMutableArray alloc] init];
        [coords addObject:location];
        [coords addObject:userLocation];
        [self.mapView addAnnotation:point];
    }
    dispatch_group_leave(group);
}];
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试在没有互联网连接的情况下使用它时,出现以下错误:

无法确定当前的国家/地区代码:错误域= …

ios clgeocoder

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

等待CLGeocoder完成并发枚举

我在类方法中有以下代码

NSDictionary *shopAddresses = [[NSDictionary alloc] initWithContentsOfFile:fileName];
NSMutableArray *shopLocations = [NSMutableArray arrayWithCapacity:shopAddresses.count];

[shopAddresses enumerateKeysAndObjectsWithOptions:NSEnumerationConcurrent usingBlock:^(id key, ShopLocation *shopLocation, BOOL *stop) {
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder geocodeAddressString:shopLocation.address completionHandler:^(NSArray *placemarks, NSError *error) {
        if (error) {
            NSLog(@"Geocode failed with error: %@", error);
        }
        else {
            shopLocation.placemark = [placemarks objectAtIndex:0];
        }
        [shopLocations addObject:shopLocation];
    }];
}
Run Code Online (Sandbox Code Playgroud)

执行此代码后,我想返回shopLocations数组作为该方法的结果.但是,如果我不希望数组为空,我需要等待所有地理编码器搜索完成.

我怎样才能做到这一点?

我尝试过不同的GCD方法,但到目前为止还没有成功.

grand-central-dispatch ios5 clgeocoder

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

iOS - MKPlacemark设置标题问题

我在设置地标的标题副标题时遇到问题.

CLGeocoder *geocoder = [[CLGeocoder alloc] init];
            [geocoder geocodeAddressString:location 
                 completionHandler:^(NSArray* placemarks, NSError* error){
                     if (placemarks && placemarks.count > 0) {
                         CLPlacemark *topResult = [placemarks objectAtIndex:0];
                         MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:topResult];

                         placemark.title = @"Some Title";
                         placemark.subtitle = @"Some subtitle";

                         MKCoordinateRegion region = self.mapView.region;
                         region.center = placemark.region.center;
                         region.span.longitudeDelta /= 8.0;
                         region.span.latitudeDelta /= 8.0;

                         [self.mapView setRegion:region animated:YES];
                         [self.mapView addAnnotation:placemark];
                     }
                 }
             ];
Run Code Online (Sandbox Code Playgroud)

placemark.title = @"Some Title";placemark.subtitle = @"Some subtitle";

给我一个错误:

Assigning to property with 'readonly' attribute …
Run Code Online (Sandbox Code Playgroud)

mkannotation ios clgeocoder

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

Google和Apple的反向地理编码比较

我需要比较GoogleApple的反向地理编码

我正在开发一款适用于iOS的应用程序并计划将其移植到Android,而Google和Apple地理编码器提供的名称将是相同的,这一点至关重要.

我比较了他们在某些地方的工作方式,但没有看到差异.但事实上,我没有找到它并不意味着没有一个.

所以我的问题是:Apple和Google反向地理编码器给出的名称是不同的?

reverse-geocoding ios google-geocoding-api clgeocoder

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

CLPlacemark在Swift中崩溃

我正在使用CLGeocoder反向地理定位并得到数组CLPlacemark.当我在美国境外使用GPS(即-27,127)然后访问时placemark.postalCode,应用程序崩溃:

"致命错误:在打开一个Optional值时意外地发现了nil".

看来,这placemark.postalCodenil没有邮政编码的地方.但是postalCodeSwift中的返回类型是String!:

var postalCode: String! { get } // zip code, eg. 95014

所以我甚至无法测试nil,因为崩溃是由吸气剂引起的postalCode.

任何想法如何防止这种崩溃?谢谢!

xcode ios clgeocoder swift clplacemark

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

Swift中的CLGeocoder - 使用reverseGeocodeLocation时无法返回字符串

我正在尝试使用CLGeocoder返回字符串中坐标的位置.我的代码目前看起来像这样:

func getPlaceName(latitude: Double, longitude: Double) -> String {

let coordinates = CLLocation(latitude: latitude, longitude: longitude)
var answer = ""

CLGeocoder().reverseGeocodeLocation(coordinates, completionHandler: {(placemarks, error) -> Void in
    if (error != nil) {
        println("Reverse geocoder failed with an error" + error.localizedDescription)
answer = ""
    }

    if placemarks.count > 0 {
        let pm = placemarks[0] as CLPlacemark
        answer = displayLocationInfo(pm)
    } else {
        println("Problems with the data received from geocoder.")
answer = ""
    }
})

return answer

}

func displayLocationInfo(placemark: CLPlacemark?) -> …
Run Code Online (Sandbox Code Playgroud)

clgeocoder swift

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