gpt4 book ai didi

ios - 在当前位置蓝点之上覆盖透明 PNG

转载 作者:行者123 更新时间:2023-11-29 04:59:03 25 4
gpt4 key购买 nike

我只是在玩苹果的 CurrentAddress 示例代码,我试图使用 trueHeading 属性来确定用户面临的方向。虽然事实证明这很简单,但我想在当前位置点的顶部显示一个透明的 PNG,并且我想旋转它以模拟指南针。

这是我目前得到的非常基本的代码:

@implementation MapViewController

@synthesize mapView, reverseGeocoder, getAddressButton;

- (void)viewDidLoad
{
[super viewDidLoad];
mapView.showsUserLocation = YES;
}



- (IBAction)reverseGeocodeCurrentLocation
{
self.reverseGeocoder =
[[[MKReverseGeocoder alloc] initWithCoordinate:mapView.userLocation.location.coordinate] autorelease];
reverseGeocoder.delegate = self;
[reverseGeocoder start];
}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error
{
NSString *errorMessage = [error localizedDescription];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Cannot obtain address."
message:errorMessage
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
[alertView release];
}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
PlacemarkViewController *placemarkViewController =
[[PlacemarkViewController alloc] initWithNibName:@"PlacemarkViewController" bundle:nil];
placemarkViewController.placemark = placemark;
[self presentModalViewController:placemarkViewController animated:YES];
}

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
// we have received our current location, so enable the "Get Current Address" button
[getAddressButton setEnabled:YES];
NSString *north = [NSString stringWithFormat:@"%f", self.mapView.userLocation.heading.trueHeading];
NSLog(@"here: %@", north);
}

@end

如何将 PNG 覆盖到蓝点的确切位置并将其保留在那里(也就是说,如果用户移动,则跟随该点)?

最佳答案

重点是您需要实现 mapView:viewForAnnotation: 委托(delegate)方法并在其中查找不属于您的注释对象。看一下截取的代码:

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation {
NSString static *defaultID = @"defaultID";
NSString static *userLocationID = @"userLocationID";

if ([annotation isKindOfClass:[MyAnnotation class]]) {
// your code here
} else {
MKAnnotationView *annotationView = [map dequeueReusableAnnotationViewWithIdentifier:userLocationID];
if (!annotationView) {
annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:userLocationID] autorelease];
annotationView.image = [UIImage imageNamed:@"UserLocationIcon.png"];
}
return annotationView;
}
}

关于ios - 在当前位置蓝点之上覆盖透明 PNG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7364339/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com