关于MKMapview中poi点的详细信息

时间:2014-09-29 04:36:25

标签: ios mkmapview point-of-interest

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

我的问题是:

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

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

1 个答案:

答案 0 :(得分: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");
         }
    ];
    
  3. 如果您需要以地图区域为中心,您可以这样做:

    - (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