我正在为 iOS 构建一个应用程序,它允许用户基于位置存储图像。现在我想使用 iOS 中最新的AnnotationView( MKMarkerAnnotationView) 来实现此目的,因为它提供了自动集群。
我的问题是,这个类需要 aglyphTintColor如果没有提供它设置为UIColor().red. iOS 使用这种颜色来为整个图像着色。之后图像就只有这种颜色。我尝试将其设置glyphTintColor为,nil但这会导致图像变红。我也尝试将其设置为,UIColor(red:1.00, green:1.00, blue:1.00, alpha:0.0)但之后图像消失了,您只能看到标记本身。
我希望标记以原始颜色而不是单色显示图像。
谁能帮我解决这个问题吗?
这是我的完整代码:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
return nil
}
let identifier = "PinAnnotationIdentifier"
var pinView = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: identifier)
pinView?.annotation = annotation
pinView?.clusteringIdentifier = "clusterId"
pinView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
pinView?.canShowCallout = false
pinView?.glyphImage = UIImage(named: "image")
return pinView
}
Run Code Online (Sandbox Code Playgroud) 我需要用我的自定义注释视图替换默认注释视图.
我需要做以下事情:
有关更多说明,请参阅图像:

在上面的图像中,我需要在图像中以圆形形式显示白色空间中的图像视图,接下来我还需要添加一个包含标签的视图,我可以在其上设置任何文本,如我,朋友,等等...
所以,为此,我搜索了关于堆栈溢出的问题,但没有得到我的答案.我不希望它在呼出时,我只是想在渲染地图时将其简单地作为注释.我试图为此制作一个自定义类,但不知道如何处理这个.
任何帮助将受到高度赞赏
我正在 MapKit/Swift 4 中开发地图,其中有很多注释。用户可以使用选择器视图选择他想要的注释(仅 1),并且该注释将被调用(就好像他已经按下了它一样)。如果方便的话,我们可以考虑改变这个注释点的颜色。关键是要在众多注释中突出显示这个特定的注释。
经过一番搜索,我发现了这个功能
func selectAnnotation(_ annotation: MKAnnotation, animated: Bool)
Run Code Online (Sandbox Code Playgroud)
我已经实现了以下功能:
func selectPoints() {
print("selectPoints called")
let annotation1 = MKPointAnnotation()
annotation1.coordinate = CLLocationCoordinate2D(latitude: 48.8596833, longitude: 2.3988939)
annotation1.title = "Temple"
annotation1.subtitle = "\(annotation1.coordinate.latitude), \(annotation1.coordinate.longitude)"
mapView.addAnnotation(annotation1)
mapView.selectAnnotation(annotation1, animated: true)
}
Run Code Online (Sandbox Code Playgroud)
因此,如果我创建一个新注释,它就可以工作,但是我如何选择以前的注释点?但我没有任何继续前进的想法或暗示。
谢谢你的帮助。
编辑:输入注释的部分代码。
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if let annotation = annotation as? Artwork {
let reuseId = "pin"
var pinView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseId)
if pinView == nil {
pinView = MKAnnotationView(annotation: annotation, reuseIdentifier: …Run Code Online (Sandbox Code Playgroud) 嗨,我的项目中有一个 MapView,我需要从 MapView 中删除所有标签注释、地点。看起来像普通的地图视图
我尝试了以下代码,它工作正常,但我仍然得到一些建筑细节、街道名称和所有我想要的也被删除的只有用户位置可见
这是代码:
[mapView setShowsPointsOfInterest:NO];
Run Code Online (Sandbox Code Playgroud)
上面的代码工作正常并从 mapKit 中删除了默认位置图标,但没有删除所有图标和标签,如何从 MapKit 中删除所有默认图标和标签名称
我有一张地图,我已经完美地添加了12个注释,我想要的是当有人点击这些注释时,它会在注释的右边有一个信息按钮,当点击时会显示注释的方向.地图应用.我已经编写了使用所需坐标打开地图应用程序的功能我只是不确定如何将信息按钮添加到注释并使其在点击时执行该功能.
编辑:我要求在Swift中完成此操作.
我不知道如何在iOS 9中更改引脚颜色的代码(因为最近Apple更改了它的代码),而且我在Swift中仍然是新手.所以,我现在不知道如何集成pinTintColor我的代码.
请在下面找到我的代码:
import UIKit
import MapKit
class ViewController: UIViewController, MKMapViewDelegate {
@IBOutlet var map: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
let annotation = MKPointAnnotation()
let latitude:CLLocationDegrees = 40.5
let longitude:CLLocationDegrees = -74.6
let latDelta:CLLocationDegrees = 150
let lonDelta:CLLocationDegrees = 150
let span:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, lonDelta)
let location:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude)
let region:MKCoordinateRegion = MKCoordinateRegionMake(location, span)
map.setRegion(region, animated: false)
annotation.coordinate = location
annotation.title = "Niagara Falls"
annotation.subtitle = "One day bla bla"
map.addAnnotation(annotation)
}
func mapView(mapView: MKMapView, viewForAnnotation …Run Code Online (Sandbox Code Playgroud) 我想知道如何annotation在拖动标题时更新我的标题,因为所有annotation属性都是get唯一的。
我尝试过的代码:
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, didChange newState: MKAnnotationViewDragState, fromOldState oldState: MKAnnotationViewDragState) {
switch (newState) {
case .starting:
//view.dragState = .dragging
print("dragging.....")
case .ending, .canceling:
// view.dragState = .none
let lat = view.annotation?.coordinate.latitude
let long = view.annotation?.coordinate.longitude
let coordinates = CLLocationCoordinate2D(latitude: lat!, longitude: long!)
print(" pin lat \(lat) long \(long)")
//Error here - title is get only property
view.annotation?.title = "New Location"
default: break
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个数组[CLLocationCoordinate2D],我想在MKMapView所有这些坐标周围画一个圆圈。
我已经成功地围绕一个圆圈画了一个圆,CLLocationCoordinate2D如下所示:
let coordinate = CLLocationCoordinate2D(latitude: 53, longitude: 27)
self.mapView.add(MKCircle(center: coordinate, radius: 100))
extension MapViewController: MKMapViewDelegate {
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
guard overlay is MKCircle else { return MKOverlayRenderer() }
let circle = MKCircleRenderer(overlay: overlay)
circle.strokeColor = UIColor.red
circle.fillColor = UIColor(red: 255, green: 0, blue: 0, alpha: 0.1)
circle.lineWidth = 1
return circle
}
}
Run Code Online (Sandbox Code Playgroud)
如何绘制一个包围/包含所有坐标的圆?,如下所示:
mapkitannotation ×10
mapkit ×9
ios ×8
swift ×4
objective-c ×2
swift2 ×2
geometry ×1
ios11 ×1
ios8 ×1
ios9 ×1
mkannotation ×1
mkmapview ×1
swift3 ×1