ios - 如何更改 MapKit 中的 markerTintColor 而不更改 Swift 中的默认位置引脚?
问题描述
我有 MKMarkerAnnotationView 来更改地图上大头针的颜色。
func mapView(_ MapView:MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?{
let view = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "pin")
view.markerTintColor = .blue
return view
}
但是,当我启动我的应用程序时,我的默认位置标记变为。如何在不更改此标记的情况下更改引脚?查看位置的代码也很简单
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
self.MapView.showsUserLocation = true
}
感谢您的回答!:)
解决方案
您可以检查注释是否是这样的用户位置:
func mapView(_ MapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
return nil
}
let view = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "pin")
view.markerTintColor = .blue
return view
}
推荐阅读
- c - 使用 Fgets 进行 malloc
- r - 如何在 R 中创建二进制变量?
- c++ - 为什么模板专业化需要 declspec?
- c++ - 为什么 std::move'ing 一个 std::map/std::unordered_map 不会让它处于不确定状态?
- c# - 为什么 Windows 服务无缘无故停止?使用 C#.net
- numpy - 在张量流中将图像转换为 (None, 224, 224, 3)
- python - 播放与矩形碰撞时如何使随机文本出现
- dictionary - Clickhouse 缓存字典中的会话超时
- c++ - 如何安装和使用 Boost.Program_options 库?
- discord.py - 如何使用 discord.py 使文本反转?