如何查看GMSPath是否包含坐标



Google Maps 1.2.0 GMSCoordinateBounds现在包含一个containsCoordinate方法,我打算用它来过滤不在可视区域上的标记。不幸的是,当您初始化GMSCoordinateBounds时,您得到的边界包含您的区域或路径。

所以我的问题是:是否有可能看到CLLocationCoordinate2D是否在GMSPath内?

所以我在回答我自己的问题。我只需要使用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;
        }
    }

最新更新