点击代表 userLocation 的脉动蓝色圆圈会弹出“当前位置”标注。有没有办法抑制它?
问问题
5879 次
7 回答
18
更新用户位置后,您可以更改注释视图上的一个属性:
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
MKAnnotationView *userLocationView = [mapView viewForAnnotation:userLocation];
userLocationView.canShowCallout = NO;
}
于 2012-04-23T16:19:19.267 回答
16
您可以将 设置title
为空白以禁止标注:
mapView.userLocation.title = @"";
编辑:
更可靠的方法可能是在didUpdateUserLocation
委托方法中空白标题:
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
userLocation.title = @"";
}
或在viewForAnnotation
:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>) annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
{
((MKUserLocation *)annotation).title = @"";
return nil;
}
...
}
在委托方法中设置标题可以让您确定您有一个真正的 userLocation 实例可以使用。
于 2011-11-29T23:34:10.993 回答
5
斯威夫特 4
// MARK: - MKMapViewDelegate
func mapViewDidFinishLoadingMap(_ mapView: MKMapView) {
if let userLocationView = mapView.view(for: mapView.userLocation) {
userLocationView.canShowCallout = false
}
}
于 2018-03-03T12:44:28.417 回答
2
斯威夫特 4 - Xcode 9.2 - iOS 11.2
// MARK: - MKMapViewDelegate
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if let userLocation = annotation as? MKUserLocation {
userLocation.title = ""
return nil
}
// ...
}
于 2018-03-17T21:29:25.540 回答
1
我有两种方法可以帮助您:
在 mapViewDidFinishLoadingMap 中抑制
func mapViewDidFinishLoadingMap(_ mapView: MKMapView) { mapView.showsUserLocation = true //suppress the title mapView.userLocation.title = "My Location" //suppress other params
}
在 didUpdate 中抑制
func mapView(_ mapView: MKMapView, didUpdate userLocation: MKUserLocation) { //suppress the title mapView.userLocation.title = "My Location" //suppress other params }
于 2017-12-05T23:48:02.377 回答
1
SWIFT 版本
添加用户 MKAnnotationView时需要将 userMKAnnotationView
属性 设置canShowCallout
为 falsemapView
func mapView(_ mapView: MKMapView, didAdd views: [MKAnnotationView]) {
for view in views {
if view.annotation is MKUserLocation {
view.canShowCallout = false
}
}
}
于 2018-05-11T16:22:40.290 回答
0
嘿,有一个更新的简单解决方案
迅速:
mapView.userLocation.title = "";
.Net for iOS (Xamarin.iOS)
NativeMap.UserLocation.Title = "";
问候 ;)
于 2020-07-22T11:10:21.480 回答