1
在我的mapView:regionDidChangeAnimated方法中,我打電話來查找地圖上的地點,但我只想在地圖移動了大量數據時進行調用。你如何測量地圖移動的距離?
下面是場景:
- 用戶移動地圖或負載
- HTTP調用get找地方
- 新增地點的地圖。
- 問題!用戶點擊一個註釋打開標題氣泡,它靠近邊緣,因此它會移動地圖。由於數據加載與地圖移動事件相關,標記消失並被重新添加。
我應該怎麼看跨度和中心點的變化?
@Scott感謝您的visibleMapRect想法。這是我到目前爲止的工作,它仍然需要考慮放大和縮小。
MKMapRect newRect = _mapView.visibleMapRect;
MKMapRect oldRect = currentRect;
float leftBoundry = (newRect.origin.x-(newRect.size.width/4));
float rightBoundry = (newRect.origin.x+(newRect.size.width/4));
float topBoundry = (newRect.origin.y-(newRect.size.height/4));
float bottomBoundry = (newRect.origin.y+(newRect.size.height/4));
NSLog(@"Origin x %f, y %f", oldRect.origin.x, oldRect.origin.y);
NSLog(@"Boundries left %f, top %f, right %f, bottom %f", leftBoundry, topBoundry, rightBoundry, bottomBoundry);
if (oldRect.origin.x < leftBoundry || oldRect.origin.x > rightBoundry || oldRect.origin.y < topBoundry || oldRect.origin.y > bottomBoundry) {
[self loadLocations];
currentRect = newRect;
}