2014-09-29 187 views
9

在iOS 8.0默認地圖應用程序中,當點擊POI點時,將獲得詳細信息,包括POI和地址的名稱。有關poi點的詳細信息MKMapview

我的問題是:

  1. 是否有可能做同樣的,因爲這使用的MKMapView或iOS本機代碼?

  2. 如果沒有,我怎麼能得到的POI數據與地圖比例尺(因爲地圖上顯示的POI點依賴於區域和規模)。因此,我需要獲取數據,以便根據此區域和比例瞭解哪個POI點顯示。

回答

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 Documentationthis beatiful example on how to manage POI with Apple Maps