gpt4 book ai didi

iOS 检查注释的坐标是否为 {0,0}

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

我有一个循环语句,它从数组中在 map View 上显示我的注释。如何检查数组中的任何坐标是否为 0,0,如果是,则删除/不绘制它们?

谢谢。

代码:

        CLLocationCoordinate2D maxCoord = {45.60250f,-122.39181f};
CLLocationCoordinate2D minCoord = {45.35697f,-123.12789f};

NSArray *callsArray = [xmlParser calls];

for (JointCAD *call in callsArray) {
NSString *callnumber = [call.callnumber stringByAppendingFormat:@". "];
NSString *callandnumber = [callnumber stringByAppendingString:call.currentCallType];
CLLocationCoordinate2D newCoord = { [call.latitude doubleValue], [call.longitude doubleValue]};

if ([call.longitude doubleValue] > maxCoord.longitude)
{
maxCoord.longitude = [call.longitude doubleValue];
}
if ([call.latitude doubleValue] > maxCoord.latitude)
{
maxCoord.latitude = [call.latitude doubleValue];
}
if ([call.longitude doubleValue] < minCoord.longitude)
{
minCoord.longitude = [call.longitude doubleValue];
}
if ([call.latitude doubleValue] < minCoord.latitude)
{
minCoord.latitude = [call.latitude doubleValue];
}

Annotation *ann = [[Annotation alloc] init];
ann.title = callandnumber;
ann.subtitle = [call location];
ann.coordinate = newCoord;
[mapView addAnnotation:ann];
}

MKCoordinateRegion region = {{0.0f, 0.0f}, {0.0f, 0.0f}};

region.center.longitude = (minCoord.longitude + maxCoord.longitude) / 2.0;
region.center.latitude = (minCoord.latitude + maxCoord.latitude) / 2.0;

region.span.longitudeDelta = (maxCoord.longitude - minCoord.longitude) * 1.1;
region.span.latitudeDelta = (maxCoord.latitude - minCoord.latitude) * 1.1;

[mapView regionThatFits:region];
[self.mapView setRegion:region animated:YES];

[self setRefreshState:@"Finished"];

最佳答案

嗯,当坐标等于 0 时,为什么不在 for 循环中添加一个 continue 呢?

在创建Annotation对象之前只需添加一个简单的

if(newCoord.latitude == 0 && newCoord.longitude == 0) continue;

继续 只是跳到循环的下一次迭代。

关于iOS 检查注释的坐标是否为 {0,0},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12991243/

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