gpt4 book ai didi

objective-c - 将地理坐标转换为 custon=m UIView 上的 CGPoint

转载 作者:搜寻专家 更新时间:2023-10-30 20:09:17 24 4
gpt4 key购买 nike

我正在构建一个应用程序,其中一个功能是在自定义 UIImageView 上推送地理坐标。我数学不好,所以我似乎无法获得正确的值(value)观。这就是我正在做的:

我有一张 2048x2048 的图像,我把它放在 UIScrollView 中,当我得到坐标时,假设是“Sydney -33.856963, 151.215219”,我将它们转换成 UIView坐标(x,y)

- (void)viewDidLoad
{
[super viewDidLoad];
scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)];
scrollView.delegate = self;
scrollView.showsVerticalScrollIndicator = YES;
scrollView.scrollEnabled = YES;
scrollView.userInteractionEnabled = YES;
[scrollView setBounces:NO];
scrollView.minimumZoomScale = 0.5;
scrollView.maximumZoomScale = 100.0;


mainImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, IMAGE_SIZE, IMAGE_SIZE)];
mainImageView.image = [UIImage imageNamed:@"map.jpg"];
mainImageView.contentMode = UIViewContentModeScaleAspectFit;
tipScroll.contentSize = CGSizeMake(IMAGE_SIZE, IMAGE_SIZE);


[scrollView addSubview:mainImageView];
[self.view addSubview:scrollView];

NSString* fileContents = @"-33.856963,151.215219";
NSArray* pointStrings = [fileContents componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

for (int i = 0; i<[pointStrings count]; i++) {
NSArray* latLonArr = [currentPointString componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@","]];
[self getCoordinates:latLonArr];

}

}
-(void)getCoordinates:(NSArray *)latLonArr{

double comparatorWidth = IMAGE_SIZE/360.0f;
double comparatorHeight = IMAGE_SIZE/180.0f;


double Xl = [[latLonArr objectAtIndex:1] doubleValue]; //151.215219
double Yl = [[latLonArr objectAtIndex:0] doubleValue]; //-33.856963

coordX = (Xl+180.0f)*comparatorWidth;
coordY = (90.0f-Yl)*comparatorHeight;

UIImage *image=[UIImage imageNamed:[NSString stringWithFormat:@"star.png"]];

imageView=[[UIImageView alloc] init];

[imageView setFrame:CGRectMake(coordX,coordY,10,10)];

[imageView setImage:image];
[scrollView addSubview:imageView];
}

我离中心坐标 (0,0) 越远,点就越不准确。如果我有西非某个城市的坐标,它就在现场,但悉尼就差很多了。我怎样才能解决这个问题?

Sydney image

最佳答案

我认为问题是地球不是平的。这意味着您不能简单地将地理坐标转换为 View 的二维系统。 http://en.wikipedia.org/wiki/Geographic_coordinate_system

检查此问题和正确答案: Converting longitude/latitude to X/Y coordinate

关于objective-c - 将地理坐标转换为 custon=m UIView 上的 CGPoint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19769524/

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