- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 ObjC 的新手,我正在努力使用 CLGeocoder。我希望能够使用 reverseGeocodeLocation
获取一个字符串,其中包含当用户按下完成按钮时我传递给我的委托(delegate)的用户位置。
所以用户触发了一个MapViewController的显示,我在viewDidLoad
中调用reverseGeocodeLocation但是 [placemarks count = 0]
这是第一次,我没有地标来获取我需要的信息。用户第二次触发 MapViewController 的显示时,placemarks 数组已被填充并且一切正常。
我怀疑这与 reverseGeocodeLocation 是一个异步调用有关 - 但我不知道如何解决这个问题。我曾尝试在线搜索,但似乎没有什么能帮助我理解我做错了什么以及如何解决这个问题。提前致谢。
@interface MapViewController ()
@property (strong, nonatomic) CLGeocoder *geocoder;
@property (readwrite, nonatomic) NSString *theLocationName;
@end
@implementation MapViewController
@synthesize mapView, geocoder, delegate = _delegate, theLocationName = _theLocationName;
- (void)viewDidLoad
{
[super viewDidLoad];
self.mapView.delegate=self;
self.mapView.showsUserLocation = YES;
[self theUserLocation];
}
-(void)theUserLocation
{
if (!geocoder)
{
geocoder = [[CLGeocoder alloc] init];
}
MKUserLocation *theLocation;
theLocation = [self.mapView userLocation];
[geocoder reverseGeocodeLocation:theLocation.location
completionHandler:^(NSArray* placemarks, NSError* error)
{
if ([placemarks count] > 0)
{
CLPlacemark *placemark = [placemarks objectAtIndex:0];
[self setTheLocationName: placemark.locality];
}
}];
- (IBAction)done:(id)sender
{
[[self delegate] mapViewControllerDidFinish:self locationName:[self theLocationName]];
}
@end
最佳答案
这不是您问题的确切答案,但是,如果您可以切换到除 CLGeocoder 之外的其他解决方案,那么以下功能可以帮助您从给定的纬度、经度获取地址
#define kGeoCodingString @"http://maps.google.com/maps/geo?q=%f,%f&output=csv" //define this at top
-(NSString *)getAddressFromLatLon:(double)pdblLatitude withLongitude:(double)pdblLongitude
{
NSString *urlString = [NSString stringWithFormat:kGeoCodingString,pdblLatitude, pdblLongitude];
NSError* error;
NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString] encoding:NSASCIIStringEncoding error:&error];
locationString = [locationString stringByReplacingOccurrencesOfString:@"\"" withString:@""];
return [locationString substringFromIndex:6];
}
关于objective-c - CLGeocoder 反向地理编码位置。第一次在 [placemarks count = 0]?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11287738/
我想获取当前位置的 country 属性。我已经在模拟器上测试了这段代码。我已经将假位置设置为 apple headquarter。 代码: - (void)viewDidLoad
如何在 MapKit 中使用自定义地标而不是标准图钉在 iPhone 上? 问候 最佳答案 您必须扩展 MKAnnotationView 类,它具有您可以设置的各种属性,图像属性是与地标图像有关的一个
我使用以下方法对谷歌地图 latlng 进行反向地理编码: [GClientGeocoder.getLocations(address:String, callback:function)][1] 其
我在使用 CLGeocoder 获取当前城市名称时遇到了一个非常奇怪的问题。我用来验证这一点的地方是 Cupertino。我 100% 确定这不是覆盖范围问题。 NSLog 正确地打印了地标,但是当它
我想在点击时为 YMKPlacemarkMapObject 设置动画。我试过了,但没有用。 func onMapObjectTap(with mapObject: YMKMapObject,
我有一个长滚动查看器,我想在滚动条上用小图像标记重要点。如果单击图像,滚动条将跳转到相应的内容。 我已经在一些应用程序中看到了这个功能,比如 Eclipse 和 Chrome。并且想知道如何用 WPF
我正在使用 Yandex Mapkit iOS SDK 对于我的一个项目。 似乎 SDK 允许添加地标是一个集群。但是我不能像添加一个地标作为 mapObject 一样使用 userData 添加自定
我正在使用这个库来获取位置: https://github.com/malcommac/SwiftLocation 在我使用该库的版本 2 之前,获取地标就像这样简单: Location.getPla
我有一个非常奇怪的问题(好吧,对我来说),我快疯了!我有一个 View Controller (X) 子类,其中我需要了解有关当前用户位置的邮政编码(和其他信息)。这样看来我可以回去了;当我重新加载
我正在用 Swift 语言开发一个应用程序,这是搜索 map 数据所必需的。因此,我使用 MKLocalSearch 实现了搜索。搜索工作完美。我将搜索结果添加到一个数组中。每当我尝试在 map 上添
在尝试使用 CLGeocoder 时,我从在线教程中获得了这个示例: https://www.appcoda.com/how-to-get-current-location-iphone-user/
我有一个 KML 文件,其中包含 GPS 坐标以及每个坐标与下一个坐标的方位角。我想检索每个坐标和每个轴承并将它们存储在单独的列表中。一个包含严格的坐标,一个包含每个坐标的方位。 为了这个问题,我将只
我收到此错误:未找到类型 'Geolocator' 并且 'Placemark' 不是类型。每当我尝试执行 flutter run 时,我都会收到此错误: lib/screens/register.d
我正在处理一个 Intranet 项目,因此我的 KML 文件无法在外部使用。这意味着我依赖 geoXML3 库将我的 XML 解析到我的 Google map 上。然而,缺乏关于事件监听器的文档令人
我在我的应用程序中添加了位置搜索栏。 tableview Controller 由用户位置纬度/经度以及目的地(地址用户输入到搜索栏中)组成。据我所知,纬度/经度在 placemark.coordin
google.maps.event.addDomListener(window, 'load', initialize); var _map; var _originMarker, _destin
我是 ObjC 的新手,我正在努力使用 CLGeocoder。我希望能够使用 reverseGeocodeLocation获取一个字符串,其中包含当用户按下完成按钮时我传递给我的委托(delegate
基本上,我需要一种方法来对搜索请求提取的所有“沃尔玛”进行注释。我没有使用界面生成器,我只是为这个应用程序使用代码。 MKMapView * map = [[MKMapView alloc] init
我的位置管理器有一个单例类,反向地理编码在我的 Viewcontroller 中,用于在应用程序中打印地址。 一切正常,直到新的 iOS 8 Beta 4 出现,现在反向地理编码不起作用——地标每次都
我对 iOS 应用程序开发有点陌生。我目前正在开发一款天气应用程序,它可以确定您的位置,然后连接到天气 API 并显示您当天的天气状况。我在从其功能中获取 placemark.locality 时遇到
我是一名优秀的程序员,十分优秀!