在iOS 8.0默认的 map 应用中,当你点击兴趣点时,你会得到包括兴趣点名称和地址在内的详细信息。
我的问题是:
是否可以使用 MKMapView 或 IOS native 代码执行与此相同的操作?
如果没有,如何获取带有 map 比例尺的POI数据(因为 map 上显示的POI点依赖于区域和比例尺)。因此,我需要获取数据以了解根据该区域和比例显示哪个 POI 点。
最佳答案
要获取包括兴趣点地址在内的详细信息,我认为您可以分两步完成:
获取您兴趣点的坐标
将它们转换为获取地址信息;看看这个漂亮的例子:
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 Documentation或 this beatiful example on how to manage POI with Apple Maps .
关于ios - MKMapview 中 poi 点的详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26092643/