capacitor-community / google-maps

Capacitor Plugin using native Google Maps SDK for Android and iOS.
https://capacitor-community.github.io/google-maps/
MIT License
153 stars 64 forks source link

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

Open J-Gonzalez opened 3 years ago

J-Gonzalez commented 3 years ago

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,
        ]])
    }
hemangsk commented 3 years ago

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.

selected-pixel-jameson commented 3 years ago

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

J-Gonzalez commented 3 years ago

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

jjozwiak commented 2 years ago

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