我有一個數百個位置的列表,只想顯示當前在屏幕上的那些位置的MKPinAnnotation。屏幕以2英里半徑的用戶當前位置開始。當然,用戶可以滾動並放大屏幕。現在,我等待地圖更新事件,然後依次通過我的位置列表,並檢查座標如下:如何確定座標是否在當前可見的地圖區域中?
-(void)mapViewDidFinishLoadingMap:(MKMapView *)mapView {
CGPoint point;
CLLocationCoordinate2D coordinate;
. . .
/* in location loop */
coordinate.latitude = [nextLocation getLatitude];
coordinate.longitude = [nextLocation getLongitude];
/* Determine if point is in view. Is there a better way then this? */
point = [mapView convertCoordinate:coordinate toPointToView:nil];
if((point.x > 0) && (point.y>0)) {
/* Add coordinate to array that is later added to mapView */
}
所以我問convertCoordinate點在哪裏就在屏幕上(除非我誤解這種方法很可能)。如果座標不在屏幕上,那麼我絕不會將它添加到mapView。
所以我的問題是,這是確定位置的lat/long是否會出現在當前視圖中並且應該添加到mapView的正確方法?或者我應該以不同的方式做到這一點?
這似乎不適用於我。出於某種原因,我的所有物品似乎都匹配。大部分x和y的值非常高。有任何想法嗎? – 2009-08-20 03:45:45
我不確定,此刻我正在旅行,無法訪問Mac。首先想到的是檢查地圖區域。但即使如此,如果點不在屏幕上(至少在我的測試中),convertCoordinate方法總是返回0.一旦我回到我的Mac前面,我將檢查它。 – ryanday 2009-08-20 22:45:52