2013-05-07 39 views
0

我想在地圖的左側顯示我的當前位置。有沒有辦法將當前位置設置爲UIMap中心以外的其他位置?

CLLocationCoordinate2D theCoordinate; 
theCoordinate.latitude = 26.926; 
theCoordinate.longitude = 75.8235; 
MKCoordinateRegion region; 
region.center = theCoordinate; 
MKCoordinateSpan span; 
span.latitudeDelta = 0.005; 
span.longitudeDelta = 0.005; 
region.span=span; 
[mapView setRegion:region animated:TRUE]; 

上面的代碼顯示在地圖的,因爲這行的中心,我的位置:

region.center = theCoordinate; 

有沒有辦法來改變這種對中心以外的任何特定位置?

謝謝。

Nitesh

+0

你想通過這個實現什麼? – Mohith 2013-05-07 13:05:04

回答

0

這不是特定於Objective-C的。如果所需的位置在地圖的左側,則需要計算中心的位置。即給定寬度爲X的像素圖和比例尺T,在我的位置以東X/2像素點的長/緯是多少。一旦你有,你可以分配

region.center = theNewCoordinate; 
0

你可以添加一種偏移?

CLLocationCoordinate2D coordinatesForCenter = [theCoordinate copy]; 

// Add an offset : 
coordinatesForCenter.latitude+=5; // 5 for exemple (it's not significant) 
coordinatesForCenter.longitude+=5; 

// Center on your new coordinates : 
region.center = coordinatesForCenter; 

希望它有幫助。

相關問題