ios - MKMapview 中 poi 点的详细信息

标签 ios mkmapview point-of-interest

在iOS 8.0默认的 map 应用中,当你点击兴趣点时,你会得到包括兴趣点名称和地址在内的详细信息。

我的问题是:

  1. 是否可以使用 MKMapView 或 IOS native 代码执行与此相同的操作?

  2. 如果没有,如何获取带有 map 比例尺的POI数据(因为 map 上显示的POI点依赖于区域和比例尺)。因此,我需要获取数据以了解根据该区域和比例显示哪个 POI 点。

最佳答案

要获取包括兴趣点地址在内的详细信息,我认为您可以分两步完成:

  1. 获取您兴趣点的坐标

  2. 将它们转换为获取地址信息;看看这个漂亮的例子:

    CLGeocoder *ceo = [[CLGeocoder alloc]init];
    CLLocation *loc = [[CLLocation alloc]initWithLatitude:32.00 longitude:21.322]; //insert your coordinates
    
    [ceo reverseGeocodeLocation:loc
          completionHandler:^(NSArray *placemarks, NSError *error) {
             CLPlacemark *placemark = [placemarks objectAtIndex:0];
             NSLog(@"placemark %@",placemark);
             //String to hold address
             NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];
             NSLog(@"addressDictionary %@", placemark.addressDictionary);
    
             NSLog(@"placemark %@",placemark.region);
             NSLog(@"placemark %@",placemark.country);  // Give Country Name
             NSLog(@"placemark %@",placemark.locality); // Extract the city name
             NSLog(@"location %@",placemark.name);
             NSLog(@"location %@",placemark.ocean);
             NSLog(@"location %@",placemark.postalCode);
             NSLog(@"location %@",placemark.subLocality);
    
             NSLog(@"location %@",placemark.location);
             //Print the location to console
             NSLog(@"I am currently at %@",locatedAt);
         }
         else {
             NSLog(@"Could not locate");
         }
    ];
    

如果您需要在您的 map 上以某个区域为中心,您可以这样做:

- (void)gotoLocation
{
    MKCoordinateRegion newRegion;

    newRegion.center.latitude = NY_LATITUDE;
    newRegion.center.longitude = NY_LONGTITUDE;

    newRegion.span.latitudeDelta = 0.5f;
    newRegion.span.longitudeDelta = 0.5f;

    [self.myMapView setRegion:newRegion animated:YES];
}

希望这些代码示例对您有所帮助:)

要了解有关 MKMapViewClass 的更多信息(我推荐它),请查看 Apple Documentationthis beatiful example on how to manage POI with Apple Maps .

关于ios - MKMapview 中 poi 点的详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26092643/

相关文章:

ios - 在 tableviewcell 中重用约束并且高度未更新

ios - 使用页面控件 ScrollView 以在 iOS 中显示图像

ios - 标注注释 View 不可点击中心

android - 如何在Google map 上搜索兴趣点?

iOS 7 悬停/点击问题 - 在某些情况下不会触发点击

iphone - 如何覆盖 UILabel 的 setFrame

ios - MKAnnotation Pin 不会拖动,即使设置为可拖动

iphone - MKMapVIew - 在点击点放置 Pin

javascript - 关闭谷歌地图本地点