iphone - 从坐标中获取位置名称?

标签 iphone objective-c ios geolocation

我已经通过坐标获取了位置名称。

使用此代码

    reverseGeocoder = [[MKReverseGeocoder alloc] initWithCoordinate:newLocation.coordinate];
    reverseGeocoder.delegate = self;
    [reverseGeocoder start];

此处 newLocation 包含我当前的位置

而reverseGeocoder是MKReverseGeocoder的类型。

我还添加了 MapKit 框架并添加了委托(delegate) MKReverseGeocoderDelegate。

并在.m文件中定义此委托(delegate)

-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{...}

当我们启动此委托(delegate)并使用 (MKPlacemark*)placemark 获取位置时,我会在上述委托(delegate)方法或任何其他用户定义的方法中的 AlertView 中显示此位置,例如:

[[[[UIAlertView alloc] initWithTitle:@"Place" 
message:[[[NSString alloc] initWithFormat:@"%@",placemark] autorelease] 
delegate:self 
cancelButtonTitle:@"Okay" 
otherButtonTitles:nil] autorelease] show];

问题是我的警报 View 每秒都会一次又一次出现。

所以请让我知道如何停止反向地理编码器或如何才能看到此警报 View 一次。

提前致谢。

最佳答案

这个问题是创建的,因为你每次都有新的位置,这个问题可以从两种方式删除...... 1)使用两个位置之间的距离条件...当您的距离大于特定距离时,您会看到警报 View ...

2)如果用户想查看一次警报,则使用此代码...

int count = 0;
-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{

.......
if(count == 0)
{
[[[[UIAlertView alloc] initWithTitle:@"Place" 
message:[[[NSString alloc] initWithFormat:@"%@",placemark] autorelease] 
delegate:self 
cancelButtonTitle:@"Okay" 
otherButtonTitles:nil] autorelease] show];

count ++;

}
}

3)概念

NSString *previousloaction;///像全局变量一样使用... NSString *currentloaction;///像全局变量一样使用...

  -(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
    {
    currentloaction=placemark;
    .......
   if(![previousloaction isEqucaltoString: currentloaction])
    {
    [[[[UIAlertView alloc] initWithTitle:@"Place" 
    message:[[[NSString alloc] initWithFormat:@"%@",placemark] autorelease] 
    delegate:self 
    cancelButtonTitle:@"Okay" 
    otherButtonTitles:nil] autorelease] show];

   previousloaction =currentloaction;

    }
    }

关于iphone - 从坐标中获取位置名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9207101/

相关文章:

iphone - Facebook SDK:发布到墙上仅出于测试目的对我可见?

iPhone 网络应用程序的 jQuery Mobile 高度问题,假定页面高度为 480 而不是 460

ios - free() 适用于 iOS 模拟器,但不适用于真实设备

ios - iOS 8 下 NSAttributedString 性能更差

ios - 需要 y 位置、高度的约束 - 自动布局 Storyboard

iphone - 带有静态单元格的 UITableViewController : contentSize is {0, 0}

iphone - iOS 10.0 Beta,键盘扩展 : The disappearing number pad (iPhone)

ios - 文件提供程序扩展,importDocumentAtURL::无法读取给定 URL 处的文件 (iOS 11.4.1)

ios - 如何使用 Firebase 和 Swift 将现有节点添加到具有不同父节点的另一个节点作为引用?

iOS PRODUCT_NAME 不是显示和包装名称