iOS 版 AR:在屏幕上显示位置(纬度、经度)

发布于 2024-11-28 02:32:05 字数 271 浏览 2 评论 0原文

我想制作一个应用程序来显示屏幕上的位置。

我将在相机图像上显示一条文本,指示用户是否正在查看它。例如,如果用户正在寻找位于其位置北部的城镇,则当他向北看时,将会看到指示该城镇的文本。

我还想显示用户和位置之间的距离。

知道用户位置后,我必须向其表明用户正在寻找另一个位置。例如,我在纽约,我想知道自由女神像在哪里。我必须知道它的纬度和经度才能在用户查看时将其显示在屏幕上。

有没有什么SDK可以实现?

您需要更多详细信息吗?抱歉,我英语说得不太好。

I want to make an app that shows where is a location on screen.

I'm going to show over camera image a text indicating if user is looking to it. For example, if user is looking for a town that is in north of his location it will see a text indicating it when he looks to the north.

I also want to show distance between user and location.

Knowing user location, I have to show it user is looking to another location. For example, I'm in New York and I want to know where is Statue of Liberty. I have to know its latitude and longitude to show it on screen when user looks at.

Is there any SDK to do it?

Do you need more details? I'm sorry, but I don't speak English very well.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

挖个坑埋了你 2024-12-05 02:32:05

步骤应该是:

  1. 获取纬度和经度并将它们设置为两个标签,self.label1 和 self.label2

  2. 创建一个具有透明颜色背景的空视图。

  3. 使用 addSubview: 将标签添加到步骤 2 中的视图。

  4. 将cameraOverlayView 设置为步骤 2 中创建的视图。

  5. 显示您的选择器。

在代码中:

在 .h 中定义:CLLocationManager *locationManager 并实现委托:

- (void)viewDidLoad {
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; //How often do you want to update your location, this sets every small change should fire an update.
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}

然后实现:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

  NSString *lat = [NSString stringWithFormat:@"%d", newLocation.coordinate.latitude];
  self.label1.text = lat;

  NSString *long = [NSString stringWithFormat:@"%d", newLocation.coordinate.longitude];
  self.label2.text = long;
}

然后在您想要向相机展示坐标的任何位置:

UIImagePickerController *picker = [[UIImagePickerController alloc] init];

picker.delegate = self;

picker.sourceType =  UIImagePickerControllerSourceTypeCamera;

emptyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; //This frame will make it fullscreen...

emptyView.backgroundColor = [UIColor transparentColor];
[emptyView setAlpha:1.0]; //I think it is not necessary,  but it wont hurt to add this line.

self.label1.frame = CGRectMake(100, 100, self.label1.frame.size.width, self.label1.frame.size.height); //Here you can specify the position in this case 100x 100y of your label1 preserving the width and height.
[emptyView addSubview:self.label1];
//Repeat for self.label2

    self.picker.cameraOverlayView = emptyView; //Which by the way is not empty any more..
    [emptyView release];
    [self presentModalViewController:self.picker animated:YES];
    [self.picker release];

希望它足够清楚,并且没有遗漏任何东西,因为我还没有对此进行测试。

Steps should be:

  1. Get lat and long and set them to two labels, self.label1 and self.label2

  2. Create an empty view with transparentColor background.

  3. Add your labels with addSubview: to the view in step 2.

  4. Set cameraOverlayView to the view created in step 2.

  5. Present your picker.

In code:

Define in your .h: CLLocationManager *locationManager and implement delegate: <CLLocationManagerDelegate>

- (void)viewDidLoad {
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; //How often do you want to update your location, this sets every small change should fire an update.
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}

Then implement:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

  NSString *lat = [NSString stringWithFormat:@"%d", newLocation.coordinate.latitude];
  self.label1.text = lat;

  NSString *long = [NSString stringWithFormat:@"%d", newLocation.coordinate.longitude];
  self.label2.text = long;
}

Then wherever you want to present your camera with coords:

UIImagePickerController *picker = [[UIImagePickerController alloc] init];

picker.delegate = self;

picker.sourceType =  UIImagePickerControllerSourceTypeCamera;

emptyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; //This frame will make it fullscreen...

emptyView.backgroundColor = [UIColor transparentColor];
[emptyView setAlpha:1.0]; //I think it is not necessary,  but it wont hurt to add this line.

self.label1.frame = CGRectMake(100, 100, self.label1.frame.size.width, self.label1.frame.size.height); //Here you can specify the position in this case 100x 100y of your label1 preserving the width and height.
[emptyView addSubview:self.label1];
//Repeat for self.label2

    self.picker.cameraOverlayView = emptyView; //Which by the way is not empty any more..
    [emptyView release];
    [self presentModalViewController:self.picker animated:YES];
    [self.picker release];

Hope its clear enough and that there isn't anything missing as i have not tested this.

寒江雪… 2024-12-05 02:32:05
  1. 像尼古拉斯建议的那样找到你的位置。
  2. 获取用户从指南针所看的方向
  3. 获取您的兴趣点的位置
  4. 根据您的坐标和兴趣点的坐标计算兴趣点的相对“航向”。
  5. 如果它位于用户标题周围,请在屏幕上显示一个包含相关信息的标签。

另一个解决方案是在 opnengl 中构建一个世界,并将您的兴趣点放入您的 OpenGL 世界中,将它们的纬度/经度值转换为您的 OpenGL 坐标。

第一个选项更容易,我认为第二个选项更灵活。

  1. get your position like Nicolas suggested.
  2. Get the direction the user is looking at from the compass
  3. Get the location of your point of interest
  4. Calculate the relative "heading" of the point-of-interes, Based on your and the point-of-interests coordinate.
  5. If it is around the user heading, show a lable on the screen with the info about it.

The other solution would be to build up a world in opnengl and place your points-of-interest into your OpenGL world, transforming their lat/lon values to your OpenGL coordinates.

The first one is much easier, I would think the second option is more flexible.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文