- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
所以我试图根据触摸 MKMapView 获取 CLLocation。然后我试图对位置进行反向地理编码。
if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
// Not sure if this is the right method to get the location or not
CLLocationCoordinate2D coordinate = [self.mapView convertPoint:[gestureRecognizer locationInView:self.mapView] toCoordinateFromView:self.mapView];
CLLocation *pinLocation = [[CLLocation alloc] initWithLatitude:coordinate.latitude longitude:coordinate.longitude];
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:pinLocation completionHandler:^(NSArray *placemarks, NSError *error) {
if (placemarks && placemarks.count > 0) {
CLPlacemark *topResult = [placemarks objectAtIndex:0];
AddressAnnotation *anAddress = [[AddressAnnotation alloc] initWithPlacemark:topResult];
[self.mapView addAnnotation:anAddress];
[self.addressesArray addObject:anAddress];
}
else {
AddressAnnotation *anAddress = [[AddressAnnotation alloc] initWithCoordinate:coordinate];
[self.mapView addAnnotation:anAddress];
[self.addressesArray addObject:anAddress];
}
}];
在我的 if/else 语句中,我想要做的是触摸 map 并获取 CLLocation。如果我可以对位置进行反向地理编码,请放下带有地址的图钉。如果我无法对位置进行反向地理编码,则放下图钉并仅在 map 标注中显示纬度和经度。
好像不行。似乎即使我在某个位置触摸 map ,反向地理编码也会使我的图钉转到反向地理编码可以定位该位置的其他地方。这不是我想要的行为。无论如何我都想放弃别针,如果我不能在标注中显示地址,只需显示纬度/经度。
如果我完全删除 revseGeocodeLocation:pinLocation 代码,只使用 else block 中的内容,那么我会得到纬度/经度,无论如何都会将 pin 放在那里。反向地理编码器是否有理由阻止我将图钉放在我想要的地方?
作为旁注,任何人都可以确认我基于 UITapGestureRecognizer 计算 CLLocationCoordinate2D 的方式是否正确?
谢谢!
最佳答案
coordinate
基于抽头点的计算看起来是正确的。
问题是当coordinate
是反向地理编码的,返回的地标可能是靠近那些坐标和CLPlacemark
的地方对象本身 ( topResult
) 包含该地点在 topResult.location.coordinate
中的精确坐标(这是注释在使用 initWithPlacemark
创建时使用的坐标)。
除非用户恰好点击了可反向地理编码的坐标,否则地标将不会准确位于他们点击的位置。
由于您希望将图钉准确放置在用户点击的位置,而不管最近找到的地标,您可以做的是覆盖 AddressAnnotation
使用的坐标。当使用地标对其进行初始化时。
例如,在调用 initWithPlacemark
之后, (假设该方法使用地标的位置设置注释的 coordinate
属性),您可以随后覆盖它:
AddressAnnotation *anAddress = [[AddressAnnotation alloc] initWithPlacemark...
anAddress.coordinate = coordinate; // <-- replace with tapped coordinate
或者,您可以使用 initWithCoordinate
而是设置 title
等手动使用来自 topResult
的信息.
此外,如果找到的地标与点击坐标的距离超过 x,请考虑在 title
前面添加前缀,例如“Near”/subtitle
向用户表明大头针不在点击的位置(例如“埃菲尔铁塔附近”)。
关于ios - 触摸 MKMapView 时的 ReverseGeocode CLLocation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12907932/
我正在使用 skobbler 的 SKMap sdk,一切都很好,但是在进一步开发时,我发现当我进行离线地理编码时,SDK 没有提供太多详细信息,这是我的要求。 我正在使用以下代码 SKSearchR
我正在尝试从坐标中找到用户的位置以保存到我的数据库中。 要查找位置名称,我正在使用 reverseGeocode。然而,由于它是一个 block 方法,我的 self.locationName 将返回
我正在将 Appcelerator Titanium 用于已上线一年多的移动应用程序。 3 天前,反向地理定位在没有任何应用程序更新的情况下停止工作。 我调试了应用程序并使用 Ti.Geolocati
所以我试图根据触摸 MKMapView 获取 CLLocation。然后我试图对位置进行反向地理编码。 if (gestureRecognizer.state == UIGestureReco
为了响应用户操作,我想将 CLLocation 转换为地址字符串并将其显示回用户。 因此顺序是1. 用户 Action 触发序列2. ReverseGeocoder 向Apple 服务器发出请求并异步
全部。 我正在使用 Google map 服务 Java 客户端 ( https://github.com/googlemaps/google-maps-services-java ) 在我的应用中提
我正在构建一个 iOS 应用程序,它在其中一个功能中实现了反向地理编码,以通过用户在 map 上的手势点击获取街道地址。 当使用 CLGeocoder 的反向地理编码功能运行应用程序时,我只能获得城市
我是一名优秀的程序员,十分优秀!