0

我想製作一個應用程序,顯示屏幕上的位置。適用於iOS的AR:顯示屏幕上位置(緯度,長度)在哪裏

我將在相機圖像上顯示一個文本,指示用戶是否正在看它。例如,如果用戶正在尋找位於他所在位置以北的城鎮,則當他向北看時,它將看到一條文字。

我也想顯示用戶和位置之間的距離。

知道用戶的位置,我必須顯示它用戶正在尋找另一個位置。例如,我在紐約,我想知道自由女神像在哪裏。當用戶看時,我必須知道它的經緯度在屏幕上顯示。

是否有任何SDK可以做到這一點?

您需要更多的細節?我很抱歉,但我的英語說得不好。

回答

3

步驟應該是:

  1. 獲取經緯度和長,並將它們設置爲兩個標籤,self.label1和self.label2

  2. 創建transparentColor背景空視圖。 2.

  3. 設置cameraOverlayView到視圖步驟第2步中

  4. 出示您的選擇器創建的視圖:

  5. 與addSubview添加標籤。

在代碼:

定義您的.h:CLLocationManager *locationManager和落實代表:<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]; 
} 

然後實現:

- (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]; 

希望它足夠清楚,沒有任何遺漏,因爲我沒有測試過這個。

+0

我不知道我是否理解你的答案。知道用戶的位置,我必須告訴用戶正在尋找另一個位置。例如,我在紐約,我想知道自由女神像在哪裏。當用戶看時,我必須知道它的經緯度在屏幕上顯示。 – VansFannel

+0

哦,我以爲你想覆蓋你的當前位置..你問的是更多的圖像識別軟件。 –

0
  1. 讓你的位置像Nicolas建議的那樣。
  2. 獲取用戶從指南針
  3. 看方向獲取您感興趣的
  4. 點的位置計算相對INTERES定點的「標題」,根據您和-點興趣協調。
  5. 如果是在用戶標題周圍,請在屏幕上用關於它的信息來顯示標籤。

另一種解決方案是在opnengl中建立一個世界,並將您的興趣點放到您的OpenGL世界中,將它們的緯度/經度值轉換爲您的OpenGL座標。

第一個更容易,我想第二個選項更靈活。

+2

0.檢查Apple的pARk示例代碼。它正在做你想要的東西 – Craig

+0

不錯的一個 - 特別是使用新的核心動作API – HeikoG

相關問題