【发布时间】: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