Google Maps for iOS - How can you tell if a marker is within the bounds of the screen?

后端 未结 5 1415
一向
一向 2020-12-31 15:11

I\'m trying to figure out a straightforward way to determine in Google Maps for iOS if a given GMSMarker is within the bounds of the visible map. There seems to be solution

5条回答
  •  北海茫月
    2020-12-31 16:11

    I have written on method to find GMSMarker is in particular frame. Set your rectangle frame (x,y,maxX,maxY). You can set any frame from screen it tell find marker is in that frame or not..

    - (BOOL)isGoogleMapMarkerVisible:(GMSMarker*)marker {
    
        //Marker point
        CGPoint markerpoint = [self.mapview.projection pointForCoordinate:marker.position];
    
        //Maximum visible region from x and y axis
        float x = 0.0;
        float y = o.o;
        float maxX = self.mapview.frame.size.width;
        float maxY = self.mapview.frame.size.height;
    
        //If marker point is on visible region return true else return false
        if (markerpoint.x > x && markerpoint.y > y && markerpoint.x < maxX && markerpoint.y < maxY) {
            return YES;
        }
        else {
                return NO;
        }
    }
    

提交回复
热议问题