iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
szuhwz
V2EX  ›  iDev

请教一下 MKMapView 的问题

  •  
  •   szuhwz · Mar 16, 2021 · 2695 views
    This topic created in 1890 days ago, the information mentioned may be changed or developed.

    以下是获取用户定位的 Delegate

    extension MapViewController: CLLocationManagerDelegate {
        func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
            if let location = locations.first{
                let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
                let span = MKCoordinateSpan(latitudeDelta: 0.075, longitudeDelta: 0.075)
                let region = MKCoordinateRegion(center: center, span: span)
                self.mapView.setRegion(mapView.regionThatFits(region), animated: false)
                locationManager.stopUpdatingLocation()
            }
        }
    }
    

    MKCoordinateSpan 的 latitudeDelta 和 longitudeDelta 数值越小地图的放大系数应该越高,但是有个问题就是用户定位(小蓝点)无法居中,并且放大系数越大,偏移量越大,如下图所示,请问一下大家有什么好的办法解决这个问题?

    6sC7Hs.png

    5 replies    2021-04-14 15:01:52 +08:00
    leon0918
        1
    leon0918  
       Mar 16, 2021
    看着不是地图中间点,用绝对中间点。另外,看看你的地图的范围,有没有被遮盖的部分。
    xoioao
        2
    xoioao  
       Mar 16, 2021
    CLLocationManager 获取到的是原始 GPS 坐标( WGS-84 ),国内使用的话,转成国测局坐标(也就是常说的火星坐标)后再赋值使用。
    szuhwz
        3
    szuhwz  
    OP
       Mar 18, 2021
    @leon0918 谢谢回复
    szuhwz
        4
    szuhwz  
    OP
       Mar 18, 2021
    @xoioao 好像是这个问题 感谢
    loveuqian
        5
    loveuqian  
       Apr 14, 2021
    好家伙,打开图片,我还以为我的黑苹果竟然有定位功能了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5340 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 57ms · UTC 08:15 · PVG 16:15 · LAX 01:15 · JFK 04:15
    ♥ Do have faith in what you're doing.