此代码根据国家/地区纬度/经度的边界框在 Google 街道地图上找到一个随机位置。但是即使使用边界框的方式来减慢它仍然 - 可能需要一分钟才能找到街景照片。我能做些什么来加快速度?
委托的方法GMSPanoramaView
检查随机位置是否有有效的全景照片。如果没有告诉找到一个新的搜索。
// Delegate method of GMSPanoramaView that get´s called when didMoveToPanorama: is called
- (void)panoramaView:(GMSPanoramaView *)view didMoveToPanorama:(GMSPanorama *)panorama
nearCoordinate:(CLLocationCoordinate2D)coordinate
{
if (!panorama)
{
[self shuffleLocation];
}
}
- (void)shuffleLocation
{
CLLocationCoordinate2D newLocation = [self randomLatitudeLongitude];
[self.panoView moveNearCoordinate:newLocation];
}
(CLLocationCoordinate2D) randomLatitudeLongitude
{
CountryBBVal auBB = [[GGData SharedInstance] boundingBoxForCountry:Australia];
double ranLongitude = [self randomDoubleBetween: auBB.NELng and: auBB.SWLng]; // Boundix Box
double ranLatitude = [self randomDoubleBetween: auBB.NELat and: auBB.SWLat];
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterDecimalStyle];
[formatter setMaximumFractionDigits:4];
[formatter setDecimalSeparator:@"."];
NSString *formattedNumberLng = [formatter stringFromNumber:@(ranLongitude)];
NSString *formattedNumberLat = [formatter stringFromNumber:@(ranLatitude)];
CLLocationCoordinate2D ranLatLng = CLLocationCoordinate2DMake([formattedNumberLat doubleValue], [formattedNumberLng doubleValue]);
//NSLog(@"ranLatLng: [%f] [%f]", ranLatLng.latitude, ranLatLng.longitude);
return ranLatLng;
}