iOS - MKMapView使用地址而不是lat / long来放置注释 [英] iOS - MKMapView place annotation by using address instead of lat / long

查看:121
本文介绍了iOS - MKMapView使用地址而不是lat / long来放置注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够通过使用纬度和经度在我的 MKMapView 上添加注释,但是,我需要使用location来获取的源是使用街道地址而不是拉特和龙。例如1234 west 1234 east,San Francisco,CA ...

I am able to place annotations on my MKMapView by using latitude and longitude, however, my feed coming in that I need to use location for is using street addresses instead of Lat and Long. e.g 1234 west 1234 east, San Francisco, CA ...

这是否与 CLLocationManager 有关?

有没有人在此之前尝试过这个?

Has anyone attempted this before?

推荐答案

基于 psoft 的优秀信息,我能够用这段代码实现我想要的。

Based on psoft's excellent information, I was able to achieve what I was looking for with this code.

NSString *location = @"some address, state, and zip";
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];

                         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];
                     }
                 }
             ];

这篇关于iOS - MKMapView使用地址而不是lat / long来放置注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆