如何查看GMSPath是否包含坐标

时间:2013-04-21 16:37:33

标签: google-maps-sdk-ios

Google地图1.2.0 GMSCoordinateBounds现在包含containsCoordinate方法,我打算用它来过滤不在visibleRegion上的标记。不幸的是,当您初始化GMSCoordinateBounds时,您将获得包含您的区域或路径的界限。

所以我的问题是:是否可以查看CLLocationCoordinate2D是否在GMSPath范围内?

1 个答案:

答案 0 :(得分:0)

所以我回答了我自己的问题。我只需要使用pointForCoordinate方法来查看该点是否在屏幕上。效果很好。

for (int i = 0; i < self.visibleLocations.count; i++) {
        Location *location = [self.visibleLocations objectAtIndex:i];
        CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake([location.lat floatValue], [location.lng floatValue]);
        CGPoint markerPoint = [self.googleMap.projection pointForCoordinate:coordinate];
        if (markerPoint.x >= 0 && markerPoint.y >= 0 && markerPoint.x <= self.googleMap.frame.size.width && markerPoint.y <= self.googleMap.frame.size.height) {
            GMSMarker *marker = [GMSMarker markerWithPosition:coordinate];
            marker.title = location.title;
            marker.icon = [UIImage imageNamed:@"search_measle_small.png"];
            marker.map = self.googleMap;
        }
    }