【问题标题】:detail information about poi point in MKMapviewMKMapview 中关于 poi 点的详细信息
【发布时间】:2023-11-08 03:57:02
【问题描述】:

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

我的问题是:

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

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

【问题讨论】:

    标签: ios mkmapview point-of-interest


    【解决方案1】:

    要获取详细信息,包括 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 Documentationthis beatiful example on how to manage POI with Apple Maps

    【讨论】: