빠른 구현을 던져서이 작업을 많은 데모로 수행했습니다. 아마추어 버전의 StreetView를 매우 단순하게 만드는 훌륭한 오픈 소스 라이브러리가 있습니다. GitHub에서 내 데모를 확인할 수 있습니다. https://github.com/ocrickard/StreetViewDemo
Google StreetView API의 heading 및 pitch 매개 변수를 사용하여 타일을 생성 할 수 있습니다. 이 타일들은 Bilal과 Geraud.ch가 제안한 것처럼 UIScrollView에 배열 될 수 있습니다. 그러나 JCTiledScrollView는 Google과 같은 이미지 위에 핀을 추가하는 꽤 좋은 주석 시스템을 포함하고 있기 때문에 JCTiledScrollView를 정말 좋아합니다. 데이터 소스/위임 구조로 인해 매우 직접적인 이미지 처리가 가능합니다.
내 구현 추적의 고기 부분 :
- (UIImage *)tiledScrollView:(JCTiledScrollView *)scrollView imageForRow:(NSInteger)row column:(NSInteger)column scale:(NSInteger)scale
{
float fov = 45.f/scale;
float heading = fmodf(column*fov, 360.f);
float pitch = (scale - row)*fov;
if(lastRequestDate) {
while(fabsf([lastRequestDate timeIntervalSinceNow]) < 0.1f) {
//continue only if the time interval is greater than 0.1 seconds
}
}
lastRequestDate = [NSDate date];
int resolution = (scale > 1.f) ? 640 : 200;
NSString *path = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/streetview?size=%dx%d&location=40.720032,-73.988354&fov=%f&heading=%f&pitch=%f&sensor=false", resolution, resolution, fov, heading, pitch];
NSError *error = nil;
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:path] options:0 error:&error];
if(error) {
NSLog(@"Error downloading image:%@", error);
}
UIImage *image = [UIImage imageWithData:data];
//Distort image using GPUImage
{
//This is where you should try to transform the image. I messed around
//with the math for awhile, and couldn't get it. Therefore, this is left
//as an exercise for the reader... :)
/*
GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:image];
GPUImageTransformFilter *stillImageFilter = [[GPUImageTransformFilter alloc] init];
[stillImageFilter forceProcessingAtSize:image.size];
//This is actually based on some math, but doesn't work...
//float xOffset = 200.f;
//CATransform3D transform = [ViewController rectToQuad:CGRectMake(0, 0, image.size.width, image.size.height) quadTLX:-xOffset quadTLY:0 quadTRX:(image.size.width+xOffset) quadTRY:0.f quadBLX:0.f quadBLY:image.size.height quadBRX:image.size.width quadBRY:image.size.height];
//[(GPUImageTransformFilter *)stillImageFilter setTransform3D:transform];
//This is me playing guess and check...
CATransform3D transform = CATransform3DIdentity;
transform.m34 = fabsf(pitch)/60.f * 0.3f;
transform = CATransform3DRotate(transform, pitch*M_PI/180.f, 1.f, 0.f, 0.f);
transform = CATransform3DScale(transform, 1.f/cosf(pitch*M_PI/180.f), sinf(pitch*M_PI/180.f) + 1.f, 1.f);
transform = CATransform3DTranslate(transform, 0.f, 0.1f * sinf(pitch*M_PI/180.f), 0.f);
[stillImageFilter setTransform3D:transform];
[stillImageSource addTarget:stillImageFilter];
[stillImageFilter prepareForImageCapture];
[stillImageSource processImage];
image = [stillImageFilter imageFromCurrentlyProcessedOutput];
*/
}
return image;
}
이제 구글은이 무한 스크롤 효과를 전체 360 학위를 얻기 위해, 당신은 당신이 관찰 어디 observeValueForKeyPath 방법에 약간의 속임수를해야 할 것 UIScrollView의 contentOffset입니다. 구현을 시작했지만 끝내지 않았습니다. 사용자가 뷰의 왼쪽 또는 오른쪽 중 하나에 도달하면 scrollView의 contentOffset
속성이 scrollView의 반대쪽으로 푸시됩니다. 콘텐츠를 올바르게 정렬 할 수 있고 contentSize를 올바르게 설정하면이 방법이 효과적입니다.
마지막으로, Google StreetView 시스템에는 초당 10 개 이미지 제한이 있으므로 사용자의 요청을 제한해야하거나 기기의 IP 주소가 특정 시간 동안 블랙리스트에 올 것입니다. 앞으로 몇 시간 동안 StreetView 요청에서 검게 칠해졌습니다. 왜냐하면 처음에는 이것을 이해하지 못했기 때문입니다.)
스트리트 뷰 API를 직접 알지 못하는 사람으로서이 점에 대해 분명히 알기 위해 그들은 3d 수학이 끝나야 만합니다. 따라서 URL 가져 오기가 마술처럼 순간적으로 이루어지면 사람들이 할 수있는 것을 실행할 수 있습니다. 카메라가 움직일 때마다 새 매개 변수를 제공하여 스트리트 뷰로 인식합니까? 그리고 당신의 질문은 이용 가능한 쿼리의 아주 작은 부분 집합을 캐싱하고 클라이언트에서 갭을 메우기 위해 자신의 3d 수학을 수행하기 위해 할 수있는 일은 무엇입니까? – Tommy
@ 토미 예, 내가 한 일은 왼쪽 및 오른쪽 버튼을 눌러 작동하는 '방향'의 paremeters를 변경할 수있는 앱을 만들었지 만 함께 180도 버전을 함께 바르고 싶습니다. – MCKapur
@ 토미 정확히, 필요합니다. 공백을 채우기 위해 클라이언트에서 3d 수학 :) – MCKapur