2013-07-13 39 views
0

我使用如下代碼更改地圖點的位置不改變縮放級別或跨度

MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(CLLocationCoordinate2DMake(annView.annotation.coordinate.latitude, annView.annotation.coordinate.longitude - .04), Some KM, Some KM); 

MKCoordinateRegion adjustedRegion = [self.mapView regionThatFits:viewRegion]; 
[self.mapView setRegion:adjustedRegion animated:YES]; 

Otherway周圍是

MKCoordinateRegionMake(CLLocationCoordinate2DMake(annView.annotation.coordinate.latitude, annView.annotation.coordinate.longitude - .04), ADD SPAN HERE) 

這兩使得地圖的縮放。我怎麼可能在沒有任何縮放的情況下改變區域。

回答

1

獲取當前區域並更改中心點。

// get current region 
MKCoordinateRegion region = self.mapView.region; 
// Update the center 
region.center = CLLocationCoordinate2DMake(annView.annotation.coordinate.latitude, annView.annotation.coordinate.longitude - .04); 
// apply the new region 
self.mapView.region = region; 
+0

該死的我怎麼錯過了這個 –

1

如果你有一個座標設置,使用MKMapView-setCenterCoordinate:animated:方法。對位置變化進行動畫處理可以讓用戶瞭解發生了什麼事情。

CLLocationCoordinate2D coordinate = annView.annotation.coordinate; 
[myMapView setCenterCoordinate:coordinate animated:YES]; 

此外,不需要做一個新的座標,只需使用已經在註解視圖中的座標。