9

在 iOS 8.0 默认地图应用程序中,当您点击 POI 点时,您将获得包括 POI 名称和地址在内的详细信息。

我的问题是:

  1. 是否可以使用 MKMapView 或 IOS 本机代码做同样的事情?

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

4

1 回答 1

4

要获取包括 POI 地址在内的详细信息,我认为您可以分两步执行此操作:

  1. 获取 POI 的坐标

  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");
         }
    ];
    

如果您需要以地图为中心的区域,您可以这样做:

- (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 文档这个关于如何使用 Apple Maps 管理 POI 的美丽示例

于 2015-06-08T13:23:04.083 回答