gpt4 book ai didi

ios - 如何移动 MKMapView 的中心,以便默认位置图标转到底部中心

转载 作者:行者123 更新时间:2023-11-29 00:47:42 25 4
gpt4 key购买 nike

我在 stackOverflow 上发现了一些与此相关的问题,例如 this one , thisthis one这里。最后一个确实有效,但问题是我在 MapKit 中使用 heading 我的意思是这个 (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *) 新标题。所以当我应用这个解决方案时,现在的问题是:

MKCoordinateRegion oldRegion = [mapView regionThatFits:MKCoordinateRegionMakeWithDistance(userLocation.location.coordinate, 800.0f, 200.0f)];
CLLocationCoordinate2D centerPointOfOldRegion = oldRegion.center;

//Create a new center point (I added a quarter of oldRegion's latitudinal span)
CLLocationCoordinate2D centerPointOfNewRegion = CLLocationCoordinate2DMake(centerPointOfOldRegion.latitude + oldRegion.span.latitudeDelta/5.0, centerPointOfOldRegion.longitude);

//Create a new region with the new center point (same span as oldRegion)
MKCoordinateRegion newRegion = MKCoordinateRegionMake(centerPointOfNewRegion, oldRegion.span);

//Set the mapView's region
[_mapView setRegion:newRegion animated:NO];

它已成功更新,但当我移动手机并访问加速度计时,它开始在新区域和旧区域之间产生抖动效果。有什么建议吗?

UPDATE
我发现这个方法可以让我更改 userLocation annotation 的默认图像,这有一个我可以设置为 myAnnotaton.center 的属性,所以这里有什么想法可以工作或如何设置它的中心吗?

- (MKAnnotationView *)mapView:(MKMapView *)mapView
viewForAnnotation:(id<MKAnnotation>)annotation {


if (annotation==(mapView.userLocation)) {
MKAnnotationView *myAnotation = [[MKAnnotationView alloc] init];

myAnotation.image = [UIImage imageNamed:@"marker"];
myAnotation.frame = CGRectMake(0, 0, 100, 100);

return myAnotation;
}
else
{
return nil;
}
}

最佳答案

您需要添加一个委托(delegate)方法来覆盖您的默认注释。

- (MKAnnotationView *)mapView:(MKMapView *)mapView
viewForAnnotation:(id<MKAnnotation>)annotation {


if (annotation==(mapView.userLocation)) {
MKAnnotationView *myAnotation = [[MKAnnotationView alloc] init];

myAnotation.image = self.userPointImage.image; //give any image here
myAnotation.centerOffset = CGPointMake(0, 250);

return myAnotation;
}
else
{
return nil;
}
}

centerOffset 会将注释设置到底部, map 将相应地旋转

关于ios - 如何移动 MKMapView 的中心,以便默认位置图标转到底部中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38451071/

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