簡體   English   中英

將用戶位置中心保留在Google地圖中-Swift

[英]Keep user location center in Google Maps - Swift

我已經將Google地圖實現為一個快捷項目,並使用locationManager跟蹤並當前打印出用戶位置。

當用戶四處移動時,我也在更改攝像頭的位置,但是隨着地圖的移動,然后藍點(用戶位置)的移動,這似乎有些生澀。

有沒有一種方法可以始終保持用戶位置居中並僅移動地圖?

您可以輕松啟用

mapView.myLocationEnabled = true

並查看此答案以獲取有關相機更新的更多信息->因為它顯示了如何使用2個位置更新相機或將位置居中

朴素,看看這個答案是否對您有幫助。 在示例代碼中,用戶位置始終處於中心位置。 雖然沒有相機的調整,但是那沒有什么不同。

希望能幫助到你。

let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)        
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))
self.map.setRegion(region, animated: true)

暫無
暫無

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

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