V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
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 · 2021-03-16 10:51:31 +08:00 · 1821 次点击
    这是一个创建于 1108 天前的主题,其中的信息可能已经有所发展或是发生改变。

    以下是获取用户定位的 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 条回复    2021-04-14 15:01:52 +08:00
    leon0918
        1
    leon0918  
       2021-03-16 11:06:46 +08:00
    看着不是地图中间点,用绝对中间点。另外,看看你的地图的范围,有没有被遮盖的部分。
    xoioao
        2
    xoioao  
       2021-03-16 15:47:45 +08:00
    CLLocationManager 获取到的是原始 GPS 坐标( WGS-84 ),国内使用的话,转成国测局坐标(也就是常说的火星坐标)后再赋值使用。
    szuhwz
        3
    szuhwz  
    OP
       2021-03-18 10:20:41 +08:00
    @leon0918 谢谢回复
    szuhwz
        4
    szuhwz  
    OP
       2021-03-18 10:21:02 +08:00
    @xoioao 好像是这个问题 感谢
    loveuqian
        5
    loveuqian  
       2021-04-14 15:01:52 +08:00
    好家伙,打开图片,我还以为我的黑苹果竟然有定位功能了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3226 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 11:56 · PVG 19:56 · LAX 04:56 · JFK 07:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.