{"id":2782,"date":"2021-05-11T20:50:59","date_gmt":"2021-05-11T12:50:59","guid":{"rendered":"http:\/\/123.57.164.21\/?p=2782"},"modified":"2021-05-11T20:50:59","modified_gmt":"2021-05-11T12:50:59","slug":"ios-mapkit-%e8%87%aa%e5%ae%9a%e4%b9%89%e7%9a%84%e5%9b%be%e9%92%89%e5%8a%a0%e6%96%87%e5%ad%97","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=2782","title":{"rendered":"IOS MapKit \u81ea\u5b9a\u4e49\u7684\u56fe\u9489\u52a0\u6587\u5b57"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/05\/image-27-1024x650.png\" alt=\"\" class=\"wp-image-2783\" width=\"461\" height=\"292\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-27-1024x650.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-27-300x191.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-27-768x488.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-27-830x527.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-27-230x146.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-27-350x222.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-27-480x305.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-27.png 1376w\" sizes=\"(max-width: 461px) 100vw, 461px\" \/><\/figure><\/div>\n\n\n\n<p>\u5728\u4f7f\u7528MapKit\u5f80\u5730\u56fe\u4e0a\u753b\u81ea\u5b9a\u4e49\u7684\u56fe\u9489\u65f6\uff0c\u6709\u65f6\u5019\u6211\u4eec\u9700\u8981\u5728\u56fe\u9489\u4e0b\u9762\u52a0\u4e9b\u6587\u5b57\u8bf4\u660e\uff0c\u53ef\u4ee5\u7528\u4e0b\u9762\u7684\u65b9\u6cd5\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">        \/\/ \u81ea\u5b9a\u4e49\u7684MKAnnotation\u4f5c\u6210\n        func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {\n            guard annotation is MKPointAnnotation else { return nil }\n\n            let identifier = \"Annotation\" + String(arc4random())\n            var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)\n            if annotationView == nil {\n                annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: identifier)\n            } else {\n                annotationView!.annotation = annotation\n            }\n\n            let image = UIImage(named: \"\\(annotation.annotationType)\")!\n            annotationView!.image = image.scaleImage(scaleSize: annotation.iconScaleSize)\n            if annotation.annotationType == \"Point\" {\n                let offset = CGPoint(x: 0, y: -(image.size.height \/ 2))\n                annotationView!.centerOffset = offset\n            }\n\n            \/\/ \u203b \u901a\u8fc7 annotationView!.addSubview \u6dfb\u52a0\u81ea\u5b9a\u4e49\u6587\u672c\n            let nameLbl: UILabel! = UILabel(frame: CGRect(x: -24, y: 40, width: 100, height: 30))\n            nameLbl.text = \"\u81ea\u7531\u6587\u672c\"\n            nameLbl.textColor = UIColor.black\n            nameLbl.font = UIFont(name: \"Atari Classic Extrasmooth\", size: 10)\n            nameLbl.textAlignment = NSTextAlignment.center\n            annotationView!.addSubview(nameLbl)\n            annotationView!.displayPriority = .required\n            return annotationView\n        }<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u4f7f\u7528MapKit\u5f80\u5730\u56fe\u4e0a\u753b\u81ea\u5b9a\u4e49\u7684\u56fe\u9489\u65f6\uff0c\u6709\u65f6\u5019\u6211\u4eec\u9700\u8981\u5728\u56fe\u9489\u4e0b\u9762\u52a0\u4e9b\u6587\u5b57\u8bf4\u660e\uff0c\u53ef\u4ee5\u7528\u4e0b\u9762\u7684\u65b9\u6cd5\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,8],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/2782"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2782"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/2782\/revisions"}],"predecessor-version":[{"id":2784,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/2782\/revisions\/2784"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2782"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2782"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2782"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}