google-maps icon indicating copy to clipboard operation
google-maps copied to clipboard

Get LatLng bounds of mapview (NE/SE/NW/SW)

Open J-Gonzalez opened this issue 4 years ago • 4 comments

Is your feature request related to a problem? Please describe. Corner bounds are extremely useful when needing to query the viewport to get points within the view.

Does this feature exist in the Google Maps SDK for android and iOS? Please link the documentation for this feature. Yes, using "visible region" https://developers.google.com/maps/documentation/android-sdk/reference/com/google/android/libraries/maps/model/VisibleRegion?hl=en

Describe the solution you'd like Either a getBounds function, or a way for all map events, such as on "didChange" to return bounds in addition to zoom level and center point lat/lng.

Additional context Example swift code on didChange event that gets this data:

    public func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {        
        self.notifyListeners("didChange", data: ["result": [
        "position": [
            "latitude": position.target.latitude,
            "longitude": position.target.longitude
        ],
        "bounds":[
            "farLeft": [
                "latitude": mapView.projection.visibleRegion().farLeft.latitude,
                "longitude": mapView.projection.visibleRegion().farLeft.longitude,
            ],
            "farRight":[
                "latitude": mapView.projection.visibleRegion().nearRight.latitude,
                "longitude": mapView.projection.visibleRegion().nearRight.longitude,
            ]
        ],
        "zoom": position.zoom,
        ]])
    }

J-Gonzalez avatar Jun 14 '21 05:06 J-Gonzalez

Hey @J-Gonzalez , sounds good to me. I'm inclined towards the getBounds function approach as it seems straightforward to implement. Would you like to send a PR for this? You've the iOS parts figured out already and android seems similar.

hemangsk avatar Jun 14 '21 15:06 hemangsk

Definitely would love to see this feature implemented as it's something we need on more then one of our projects.

selected-pixel-jameson avatar Jun 15 '21 10:06 selected-pixel-jameson

Opened up PR https://github.com/capacitor-community/capacitor-googlemaps-native/pull/81 that creates this functionality via a viewBounds() function.

J-Gonzalez avatar Jun 16 '21 08:06 J-Gonzalez

Hello @hemangsk it looks like this enhancement exists on the v1 branch so it's not showing up when installing via npm which I imagine is pointing to the main branch.

Is this enhancement working? If so, is there a plan to merge into the main branch?

Working on a project currently that requires this capability. Thank you!

UPDATE: I just submitted a PR #171 with a modified version of @J-Gonzalez 's code so this can be merged into main

jjozwiak avatar May 06 '22 16:05 jjozwiak