2010-03-29 3 views
3

기본적으로 사용자 위치와 선택한 위치 목록을지도에 표시하려고합니다. 그것은 심지어 표준 아이폰 주석을 가질 수 있습니다. 그러나 나는 이것을 달성하기 위해 내가 취할 수있는 일반적인 단계를 전혀 모른다. MKMapView, Core Location 또는 둘 다 사용합니까? 누군가 나에게 걸릴 단계에 대한 간단한 개요 나 좋은 자습서 나 샘플 코드에 대한 링크를 줄 수 있습니까? 감사합니다iPhone의지도에서 사용자의 위치와 추가 지점을 어떻게 표시합니까?

확장하려면 위치 배열을 처리하는 방법에 대한 예제가있는 곳이 있는지 궁금합니다. 사용자 위치를 확인한 다음 사용자로부터 멀리 떨어진 위치를 참조하려는 반경을 설정 한 다음 그 반경 내에 맞는 위치 배열로 반경을 채울 필요가 있다고 생각합니다. 내 생각이 맞습니까? 그리고이 부분의 적어도 일부를 수행하는 방법에 대한 예가 나와 있습니다. 단일 위치를 표시하는 방법에 대한 많은 예제를 보았지만 여러 위치를 다루는 예제는 없었습니다.

답변

3
+0

도움을 주셔서 감사합니다. 그러나 이미 몇 가지 Google 검색을 통해 이러한 링크를 보았습니다. 이 자습서는 매우 간단하며 단일 위치에만 적용됩니다. 더 발전된 것이 있습니까? – gravityone

5

가 여기에 당신을 도울 수를 사용하고 뭔가. CLLocations의 배열에 맞는 MKCoordinateRegion을 제공합니다. 그런 다음 MKMapView setRegion에 전달하기 위해 그 지역을 사용할 수 있습니다 : 애니메이션 : 당신은 아마 이미 설립하고, 당신은 당신이 원하는 것을 할 수있는 MKMapView 및 핵심 위치를 사용하는

// create a region that fill fit all the locations in it 
+ (MKCoordinateRegion) getRegionThatFitsLocations:(NSArray *)locations { 
    // initialize to minimums, maximums 
    CLLocationDegrees minLatitude = 90; 
    CLLocationDegrees maxLatitude = -90; 
    CLLocationDegrees minLongitude = 180; 
    CLLocationDegrees maxLongitude = -180; 

    // establish the min and max latitude and longitude 
    // of all the locations in the array 
    for (CLLocation *location in locations) { 
     if (location.coordinate.latitude < minLatitude) { 
      minLatitude = location.coordinate.latitude; 
     } 
     if (location.coordinate.latitude > maxLatitude) { 
      maxLatitude = location.coordinate.latitude; 
     } 
     if (location.coordinate.longitude < minLongitude) { 
      minLongitude = location.coordinate.longitude; 
     } 
     if (location.coordinate.longitude > maxLongitude) { 
      maxLongitude = location.coordinate.longitude; 
     } 
    } 

    MKCoordinateSpan span; 
    CLLocationCoordinate2D center; 
    if ([locations count] > 1) { 
     // for more than one location, the span is the diff between 
     // min and max latitude and longitude 
     span = MKCoordinateSpanMake(maxLatitude - minLatitude, maxLongitude - minLongitude); 
     // and the center is the min + the span (width)/2 
     center.latitude = minLatitude + span.latitudeDelta/2; 
     center.longitude = minLongitude + span.longitudeDelta/2; 
    } else { 
     // for a single location make a fixed size span (pretty close in zoom) 
     span = MKCoordinateSpanMake(0.01, 0.01); 
     // and the center equal to the coords of the single point 
     // which will be the coords of the min (or max) coords 
     center.latitude = minLatitude; 
     center.longitude = minLongitude; 
    } 

    // create a region from the center and span 
    return MKCoordinateRegionMake(center, span); 
} 

해야합니다. 내 애플 리케이션에서 내가 표시하고자하는 위치를 알고, 다음 모든 MKMapView 그들을 충분히 넣을 정도로 큰. 위의 방법을 그렇게 도움이 될 것입니다. 그러나 주어진지도 영역에 맞는 위치 목록을 얻고 싶다면 위의 작업과 반대되는 작업을 수행해야합니다.

+0

이것은 Apple Watch =에 대한 WKInterfaceMap의 "zoom to fit"에도 적용됩니다. – DiscDev

관련 문제