谷歌地图iOS SDK:优化查找随机街景



此代码根据一个国家的纬度/经度的边界框在谷歌街道地图上找到一个随机位置。但即使有了边界框,速度仍然很慢——可能需要一分钟才能找到一张骏马视角的照片。我能做些什么让它更快?

来自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;
}

您所拥有的是一种不确定的查找照片的方法,因此您无法控制它需要多长时间。您所编码的内容是最优的,并且在代码中没有任何性能改进。只有你的算法才能做到这一点,你需要想出一个更好的策略来获得随机照片。

最新更新