SwiftUI custom MapAnnotation All In One
SwiftUI custom MapAnnotation All In One
error
Initializer 'init(coordinateRegion:interactionModes:showsUserLocation:userTrackingMode:annotationItems:annotationContent:)' requires that 'MapAnnotationView' conform to 'MapAnnotationProtocol'
var body: some View {
// $var 引用类型, var 值类型
// Map(coordinateRegion: $region)
Map(coordinateRegion: $region, annotationItems: locations) { location in
// MapPin(coordinate: location.location, tint: .accentColor)
// MapMarker(coordinate: location.location, tint: .accentColor)
// 自定义标注
/*
MapAnnotation(coordinate: location.location) {
Image("Logo")
.resizable()
.scaledToFit()
.frame(width: 20, height: 20, alignment: .center)
}
*/
MapAnnotationView(location);
}
}
solution
// MapAnnotationProtocol
var body: some View {
// $var 引用类型, var 值类型
// Map(coordinateRegion: $region)
Map(coordinateRegion: $region, annotationItems: locations) { location in
// MapAnnotation ✅
MapAnnotation(coordinate: location.location) {
// 自定义标注 ✅
MapAnnotationView(location)
}
}
}
refs
https://swiftwithmajid.com/2020/07/29/using-mapkit-with-swiftui/
https://www.appcoda.com/swiftui-map/
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/16341542.html
未经授权禁止转载,违者必究!