使用地图visibleRegion搜索CoreData

时间:2013-04-14 21:18:10

标签: ios5 core-data google-maps-sdk-ios geohashing

我在CoreData中存储了数千个位置,我想搜索Google Maps visibleRegion范围内的位置。我之前使用边界框进行搜索,但添加bearing feature会破坏此类查询。我有几个想法,但这必须是一些经过深思熟虑的解决方案的常见问题。我有兴趣看看是否有任何解决方案使用geohashes。

这是我的查询,当轴承未到达时会中断。

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(lat > %f AND lat < %f AND lng > %f AND lng < %f)",
                                    [self.googleMap.projection visibleRegion].nearLeft.latitude,
                                    [self.googleMap.projection visibleRegion].farLeft.latitude,
                                    [self.googleMap.projection visibleRegion].nearLeft.longitude,
                                    [self.googleMap.projection visibleRegion].nearRight.longitude
                               ];

1 个答案:

答案 0 :(得分:0)

您可以计算可见区域的轴对齐边界框,然后使用它来查找您的位置。其中一些仍然在实际可见区域之外,但至少你会过滤掉大部分区域。

GMSCoordinateBounds中的GMSCoordinateBounds.h类可用于简化此操作:

GMSMapView* _mapView = ...;

GMSCoordinateBounds* bounds = 
    [[GMSCoordinateBounds alloc] 
        initWithRegion: [_mapView.projection visibleRegion]];
CLLocationCoordinate2D northEast = bounds.northEast;
CLLocationCoordinate2D southWest = bounds.southWest;

另请注意,目前有一个visibleRegion太大的错误,请参见此处:

https://code.google.com/p/gmaps-api-issues/issues/detail?id=5107

请参阅此处了解该问题的解决方法:

Google Maps iOS SDK: How do I get accurate latitude and longitude coordinates from a camera's visibleRegion?

相关问题