Dai*_*jan 6

路径由坐标组成.mapview有一个可见区域.您可以轻松检查坐标是否在某个区域内,甚至不会进入像素空间:

- (void)checkPath:(GMSPath*)path {
    GMSVisibleRegion visibleRegion = _googleMap.projection.visibleRegion;
    GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithRegion: visibleRegion];

    for(int i = 0; i < path.count; i++) {
        CLLocationCoordinate2D coordinate=[path coordinateAtIndex:i];
        if([bounds containsCoordinate:coordinate]) {
            NSLog("Visible");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)


Sun*_*hah 0

使用pointForCoordinatemapview的方法来查看路径的给定点是否会出现在屏幕上

for (int i = 0; i < path.count; i++) {
            CLLocationCoordinate2D coordinate=[path coordinateAtIndex:i];
            CGPoint markerPoint = [mapView_.projection pointForCoordinate:coordinate];

            if (markerPoint.x >= 0 && markerPoint.y >= 0 && markerPoint.x <= mapView_.frame.size.width && markerPoint.y <= mapView_.frame.size.height) {
                NSLog(@"Visible");
            }
        }
Run Code Online (Sandbox Code Playgroud)