我有很多MKMapViews,每个都有一个注释。我正在尝试以这种方式检索每个坐标:
for (MKMapView *map in MapViewArray)
{
// add textfield contents to array
NSString *latitude = [NSString stringWithFormat:@"%@", map.annotations];
[latitudes addObject: latitude];
}
我正在寻找正确的代码,而不是这个:
map.annotations
我想在这里找到纬度。
我该怎么做??
每个地图注记都是一个对象,因此您必须从注记中获取坐标值。注解存储在数组map.annotations
中。如果每个地图只有一个注记,则可以使用以下内容:
CLLocationCoordinate2D coordinate = [[map.annotations lastObject] coordinate];
NSString *latitude = [NSString stringWithFormat:@"%.2f", coordinate.latitude];
如果您有多个注释,则显然必须单独遍历每个注释,然后获取位置数据。