2013-05-06 4 views
1

에서 나는 나를 나 해당 상자 내에서 결과를 반환 할 수 있습니다 좌표의 "경계 상자"를 지정할 수 있도록하는 API 함께 일하고 :찾기 경계 상자 CLLocationCoordinate2D

  • 은 내부 지오 캐시의리스트를 돌려줍니다 지정된 테두리 상자 을 상자 중앙에서부터 정렬합니다.
  • 매개 변수 남쪽 범위 위도, 서 경도, 북위도, 동경은 경계 상자의 가장자리 인 을 정의합니다.
  • 좌표는 십진수 여야합니다. 북위도와 동경경에는 각각 양수를 사용하고 남위 위도와 서 경도는 음수를 사용하십시오.
  • 상자는 경도 180 ° 또는 90 ° 또는 -90 °를 넘을 수 없습니다.

    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(self.mapView.centerCoordinate, 2000.0, 2000.0); 
    CLLocationCoordinate2D northWestCorner, southEastCorner; 
    northWestCorner.latitude = center.latitude - (region.span.latitudeDelta/2.0); 
    northWestCorner.longitude = center.longitude + (region.span.longitudeDelta/2.0); 
    southEastCorner.latitude = center.latitude + (region.span.latitudeDelta/2.0); 
    southEastCorner.longitude = center.longitude - (region.span.longitudeDelta/2.0); 
    

    사람이 어떻게 내가 할 수있는 알고 있나요 : 그것은 내가 API에 필요한 것입니다

이의 수학은 내 능력 밖 조금이지만, 나는 다소 도움이 계산을 찾았지만, 나는 확실하지 않다 이 작업을 수행? 바운딩 박스의 가장자리를 정의하는 west longitude, north latitude, east longitude을 얻기 위해 계산이 도움이되지 않습니까?

편집 :

오류 나는 점점 오전 :

Invalid value for parameter: bbox=south,west,north,east

가 중심 값을 사용하여 :

center=37.552821,-122.377413

(위에서 계산 한 후) 박스 변환 :

bbox=37.561831,-122.388730,37.543811,-122.366096

최종 작업 코드 :

// Current distance 
MKMapRect mRect = mapView.visibleMapRect; 
MKMapPoint eastMapPoint = MKMapPointMake(MKMapRectGetMinX(mRect), MKMapRectGetMidY(mRect)); 
MKMapPoint westMapPoint = MKMapPointMake(MKMapRectGetMaxX(mRect), MKMapRectGetMidY(mRect)); 
CLLocationDistance distance = MKMetersBetweenMapPoints(eastMapPoint, westMapPoint); 

// Region 
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(request.center, distance, distance); 
CLLocationCoordinate2D northWestCorner, southEastCorner; 
northWestCorner.latitude = request.center.latitude + (region.span.latitudeDelta/2.0); 
northWestCorner.longitude = request.center.longitude - (region.span.longitudeDelta/2.0); 
southEastCorner.latitude = request.center.latitude - (region.span.latitudeDelta/2.0); 
southEastCorner.longitude = request.center.longitude + (region.span.longitudeDelta/2.0); 
base = [base stringByAppendingFormat:@"bbox=%f,%f,%f,%f&", southEastCorner.latitude,northWestCorner.longitude,northWestCorner.latitude,southEastCorner.longitude]; 

답변

2

당신은 것은 반구 반전 입수했습니다 수 있습니다. 북쪽과 동쪽은 양성입니다. 따라서 중심 위도에서 시작하여 북쪽 경계를 찾으려면 델타의 절반을 빼고 빼십시오.

+0

그래서, 내 모든 플러스를 마이너스로 바꾸고 비자를 반대로 바꿔야한다고 말하는 것입니까? –

+0

네, 그러면 올바른 northWestCorner와 southEastCorner를 얻을 수 있습니다. 아직 시도해 봤어? – Craig

+0

그래, 내가 말한 것을 고치려고했다. 그런 다음'base = [base stringByAppendingFormat : @ "bbox = % f, % f, % f, % f &", northWestCorner.latitude, northWestCorner.longitude, southEastCorner.latitude, southEastCorner.longitude];'그리고 그것은 여전히 ​​나에게 오류를 준다. 당신이 필요하다고 생각하는 코드를 게시 할 수 있습니까? 이 문제가 제대로 발생하는지 잘 모르겠습니다. –