gpt4 book ai didi

xcode - 尝试在 Pin (MKMapView) 上居中 map

转载 作者:行者123 更新时间:2023-12-04 13:07:17 25 4
gpt4 key购买 nike

正在努力寻找一种方法来使 map 缩放并以注释图钉为中心。 Pin 掉落,但 map 加载海洋。代码如下。

- (void) connectionDidFinishLoading:(NSURLConnection *)connection
{
[self setString];

NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:nil];
NSDictionary *location = [dic objectForKey:@"location"];
NSDictionary *coordinate = [location objectForKey:@"coordinate"];
NSString *lat = [coordinate objectForKey:@"latitude"];
NSString *lon = [coordinate objectForKey:@"longitude"];

for (NSDictionary *diction in coordinate)
{
[array addObject:lat];
[array addObject:lon];
}
{
CLLocationCoordinate2D track;
track.latitude = [lat doubleValue];
track.longitude = [lon doubleValue];

MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc] initWithTitle:@"Title of Place Here" andCoordinate:track];

[self.mapView addAnnotation:newAnnotation];
}
}

第二个问题,非常相关:

在实现上述问题的答案后,我修改了我的代码。现在,我的坐标从前一个 View 进入我的 MKMapView,这样我就不必费心进行两次 API 调用,第二次是在 MKMapView 中。目前在我的 ViewWillAppear 中,我有以下内容,并且再次遇到 View 无法居中和放大图钉的问题:
if ([self.stringToDisplay isEqualToString: @"Firehouse Gallery"])
{
UIImage *img = [UIImage imageNamed:@"firehouse.jpg"];
[imageView setImage:img];

CLLocationCoordinate2D track;
track.latitude = [lat doubleValue];
track.longitude = [lon doubleValue];

MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta = 0.01;
span.longitudeDelta = 0.01;
region.span = span;
region.center = track;

MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc] initWithTitle:@"Firehouse Gallery" andCoordinate:track];

[self.mapView addAnnotation:newAnnotation];
[self.mapView setRegion:region animated:TRUE];
[self.mapView regionThatFits:region];
}

非常感谢反馈,因为我不知道我还应该做什么。引脚加载到正确的坐标上,只是不居中/缩放...

最佳答案

尝试这个:

{
CLLocationCoordinate2D track;
track.latitude = [lat doubleValue];
track.longitude = [lon doubleValue];

MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta = 0.01;
span.longitudeDelta = 0.01;
region.span = span;
region.center = track;

MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc] initWithTitle:@"Title of Place Here" andCoordinate:track];

[self.mapView addAnnotation:newAnnotation];
[self.mapView setRegion:region animated:TRUE];
[self.mapView regionThatFits:region];
}

关于xcode - 尝试在 Pin (MKMapView) 上居中 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14866812/

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