如何在 mkmapview type=satellite 中更改用户位置图钉图像?
how to change user location pin image in mkmapview type=satellite?
在 MKMapView
中,我有两种类型的地图,即 MKMapTypeStandard
和 MKMapTypeSatellite
。
我想将用户位置图钉替换为另一个(location.jpg) 图片。
图钉图像在 MKMapTypeStandard
(location.jpg) 中发生变化,但在 MKMapTypeSatellite
(默认图像)中图钉图像显示为默认地图图钉图像。
我如何解决这个问题项目?
这是我的代码。
MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:nil];
MKPinAnnotationView *customPinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];
//customPinView.image = [UIImage imageNamed:@"mappin4"];
if (!pinView)
{
if (annotation == mapView.userLocation)
{
customPinView.image = [UIImage imageNamed:@"mappin4"];
}
else
{
}
customPinView.animatesDrop = NO;
customPinView.canShowCallout = NO;
customPinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
return customPinView;
} else
{
pinView.annotation = annotation;
}
这样试试;
- (void) changeMapType: (id)sender
{
if (mapView.mapType == MKMapTypeStandard)
mapView.mapType = MKMapTypeSatellite;
else
mapView.mapType = MKMapTypeStandard;
}
所以默认情况下,如果您使用 google 地图,它的格式是 MKMapTypeStandard。
你可以根据需要更改 mapView.mapType = MKMapTypeSatellite;
您还可以查看以下内容 url ;
Why does a custom MKMapView annotation image disappear on touch?
确保您在 viewForAnnotation 方法中到处都使用 MKAnnotationView 而不是 MKPinAnnotationView。
在 MKMapView
中,我有两种类型的地图,即 MKMapTypeStandard
和 MKMapTypeSatellite
。
我想将用户位置图钉替换为另一个(location.jpg) 图片。
图钉图像在 MKMapTypeStandard
(location.jpg) 中发生变化,但在 MKMapTypeSatellite
(默认图像)中图钉图像显示为默认地图图钉图像。
我如何解决这个问题项目?
这是我的代码。
MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:nil];
MKPinAnnotationView *customPinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];
//customPinView.image = [UIImage imageNamed:@"mappin4"];
if (!pinView)
{
if (annotation == mapView.userLocation)
{
customPinView.image = [UIImage imageNamed:@"mappin4"];
}
else
{
}
customPinView.animatesDrop = NO;
customPinView.canShowCallout = NO;
customPinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
return customPinView;
} else
{
pinView.annotation = annotation;
}
这样试试;
- (void) changeMapType: (id)sender
{
if (mapView.mapType == MKMapTypeStandard)
mapView.mapType = MKMapTypeSatellite;
else
mapView.mapType = MKMapTypeStandard;
}
所以默认情况下,如果您使用 google 地图,它的格式是 MKMapTypeStandard。 你可以根据需要更改 mapView.mapType = MKMapTypeSatellite;
您还可以查看以下内容 url ;
Why does a custom MKMapView annotation image disappear on touch?
确保您在 viewForAnnotation 方法中到处都使用 MKAnnotationView 而不是 MKPinAnnotationView。