gpt4 book ai didi

ios - map 不缩放到坐标

转载 作者:行者123 更新时间:2023-11-28 22:26:54 24 4
gpt4 key购买 nike

我的 map 应该缩放到保存在 NSUserDefaults 中的位置。虽然我的图钉显示在 map 上,但 map 转到海洋并且根本没有缩放。这是我的代码。我做错了什么?

我确实定义了#define METERS_PER_MILE 1609.344

-(void)viewWillAppear:(BOOL)animated{

NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
if ([ud boolForKey:@"headquarters_coordinates"])
{
CLLocationCoordinate2D savedCoordinate;
savedCoordinate.latitude = [ud doubleForKey:@"headquarters_latitude"];
savedCoordinate.longitude = [ud doubleForKey:@"headquarters_longitude"];
//create annotation object using savedCoordinate and add to map view...
NSLog(@"Your HQ is at coordinates %f and %f",savedCoordinate.latitude, savedCoordinate.longitude);



MapViewAnnotation *ann1 =[[MapViewAnnotation alloc] init];
ann1.title=@"HQ";
ann1.subtitle=@"";
ann1.coordinate= savedCoordinate;
[mapView addAnnotation:ann1];



MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(savedCoordinate, 0.5*METERS_PER_MILE, 0.5*METERS_PER_MILE);


[mapView setRegion:viewRegion animated:YES];

}

}

最佳答案

这是我的代码示例,希望对您有所帮助(我认为您应该在代码中插入“MKCoordinateRegion adjustedRegion = [mapView regionThatFits:viewRegion];”)。如果您希望缩放动画,请将您的代码移动到 viewdidapear。

#define METERS_PER_MILE 1609.344

CLLocationCoordinate2D zoomLocation;
zoomLocation.latitude =[mylatitude floatValue];
zoomLocation.longitude = [mylongitude floatValue];

MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 0.1*METERS_PER_MILE, 0.1*METERS_PER_MILE);
MKCoordinateRegion adjustedRegion = [mapViewElement regionThatFits:viewRegion];
[mapViewElement setRegion:adjustedRegion animated:YES];

关于ios - map 不缩放到坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18689430/

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