Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(google-maps): make LatLngBounds contains and extend optional #1801

Closed
djabif opened this issue Sep 19, 2023 · 2 comments
Closed

feat(google-maps): make LatLngBounds contains and extend optional #1801

djabif opened this issue Sep 19, 2023 · 2 comments
Labels

Comments

@djabif
Copy link

djabif commented Sep 19, 2023

Feature Request

Plugin

Google Maps

Description

I'm trying to use the map.fitBounds() method which has a LatLngBounds param.

The LatLngBounds class is defined as:

export declare class LatLngBounds {
    southwest: LatLng;
    center: LatLng;
    northeast: LatLng;
    constructor(bounds: LatLngBoundsInterface);
    contains(point: LatLng): Promise<boolean>;
    extend(point: LatLng): Promise<LatLngBounds>;
}

If I do the following I get a compilation error of: "Error: Module not found: Error: Can't resolve '@capacitor/google-maps/dist/typings/definitions'"

const latLngBounds = new LatLngBounds({ southwest, center, northeast });
await this.map?.fitBounds(latLngBounds, 50);

I'm importing LatLngBounds from the plugin typings.

import { LatLngBounds } from '@capacitor/google-maps/dist/typings/definitions';

So I tried creating the LatLngBounds object without the constructor. It works on the web but in capacitor I get the error: "DataCloneError: The object can not be cloned." and the fitBounds doesn't work.

 const latLngBounds: LatLngBounds = {
        southwest,
        center,
        northeast,
        contains: function (point: LatLng): Promise<boolean> {
          throw new Error('Function not implemented.');
        },
        extend: function (point: LatLng): Promise<LatLngBounds> {
          throw new Error('Function not implemented.');
        }
 }; 
await this.map?.fitBounds(latLngBounds, 50);

Platform(s)

All

Preferred Solution

Modify LatLngBounds class to have contains and extend methods optional.

export declare class LatLngBounds {
    southwest: LatLng;
    center: LatLng;
    northeast: LatLng;
    constructor(bounds: LatLngBoundsInterface);
    contains?(point: LatLng): Promise<boolean>;
    extend?(point: LatLng): Promise<LatLngBounds>;
}

Doing this, I'm able to create the LatLngBounds without the constructor like this and works fine in all platforms:

 const latLngBounds: LatLngBounds = {
        southwest,
        center,
        northeast
};
@ionitron-bot ionitron-bot bot added the triage label Sep 19, 2023
@djabif
Copy link
Author

djabif commented Oct 16, 2023

I was able to fix it using the LatLngBoundsInterface

const latLngBounds: LatLngBoundsInterface = {
      southwest: { lat: southwest.lat(), lng: southwest.lng() },
      center,
      northeast: { lat: northeast.lat(), lng: northeast.lng() }
};

const bounds = new LatLngBounds(latLngBounds);
await gMap?.fitBounds(bounds, 20);

@djabif djabif closed this as completed Oct 16, 2023
Copy link

ionitron-bot bot commented Oct 31, 2023

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of the plugin, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Oct 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant