簡體   English   中英

以用戶位置為中心的地圖

[英]Centering map against user's location

我想將地圖(mapkit)對准用戶的位置。 我在模擬器中執行以下操作,但只得到沒有內容的藍色地圖。 我應該采取什么步驟?

MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.2;
span.longitudeDelta=0.2;

CLLocationCoordinate2D location;
location.latitude = mapView.userLocation.location.coordinate.latitude;
location.longitude = mapView.userLocation.location.coordinate.longitude;

region.span=span;
region.center=location;
[self.mapView setRegion:region animated:TRUE];
[self.mapView regionThatFits:region];

上面的long / lat值是:

location.latitude = 1.0256307104653269e-305
location.longitude = 1.2742349910917941e-313

-編輯-
我在這里找到了后續評論的答案: Mapkit UserLocation found event 與下面的答案一起使用,可以提供解決方案。

沒有內容的藍色地圖通常表示您在海洋中的某個地方。 縮小並檢查坐標,您最有可能在非洲海岸的緯度0.0和經度0.0。 您是否檢查過您的經度和緯度值?

您也可以嘗試將-setCenterCoordinate: animated:userLocation中心一起使用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM