【问题标题】:Google Maps iOS SDK: optimizing finding a random street viewGoogle Maps iOS SDK:优化查找随机街景
【发布时间】:2013-08-13 14:18:00
【问题描述】:

此代码根据国家/地区纬度/经度的边界框在 Google 街道地图上找到一个随机位置。但是即使使用边界框的方式来减慢它仍然 - 可能需要一分钟才能找到街景照片。我该怎么做才能加快速度?

GMSPanoramaView 的委托方法检查随机位置是否有有效的全景照片。 if not 告诉寻找一个新的搜索。

// 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;
}

【问题讨论】:

    标签: ios objective-c google-maps google-street-view


    【解决方案1】:

    您所拥有的是一种不确定的查找照片的方式,因此您无法控制需要多长时间。您编写的代码是最佳的,并且代码没有性能改进。只有您的算法不是最佳的,您需要考虑更好的策略来获取随机照片。

    【讨论】:

    • 是的,如果有某种方式 moveNearCoordinate: (google SDK 的一部分) 不要那么挑剔,而是按照名称的含义进行操作,并找到最近的坐标,这将起作用。我想如果我想要另一个 moveNearCoordinate: 方法,我需要直接访问 Google Maps API
    • 好吧,Google SDK 不是照片查找 API,所以想办法在边界框中查找照片。
    猜你喜欢
    • 2013-07-14
    • 1970-01-01
    • 2017-11-12
    • 1970-01-01
    • 1970-01-01
    • 2016-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多