Google-map-react: fitBounds is not in typings

Created on 16 May 2019  路  3Comments  路  Source: google-map-react/google-map-react

First thank you all for this great library

the issue: fitBounds is not in typescript typings
if i import { fitBounds } from 'google-map-react/utils';
typescript complains with Could not find a declaration file for module 'google-map-react/utils'.
i don't know if maybe i'm importing it wrong.

Thank you for your time.

Most helpful comment

@edgarjrg I would recommend you to use googleMaps.fitBounds, something like how I did it here in google-map-react-examples

All 3 comments

@edgarjrg i use google maps own fitBounds method for this.

First off you need to tell GoogleMapReact to use GoogleMapApi:

private googleMaps: google.maps.Map;

public render() {

    return (
        <GoogleMapReact
            onGoogleApiLoaded={this.handleGoogleApiLoaded}
            yesIWantToUseGoogleMapApiInternals={true}
            ...
        >
            {some component}
        </GoogleMapReact
    );
}

then:

private handleGoogleApiLoaded(maps: { map: google.maps.Map; }) {

    this.googleMaps = maps.map;

    const bounds = {
        north: boundingBox[1].latitude,
        east: boundingBox[1].longitude,
        south: boundingBox[0].latitude,
        west: boundingBox[0].longitude,
    };

    this.googleMaps.fitBounds(bounds);
}

the typings are coming from:

"@types/googlemaps": "3.30.x",

Thank you @vertic4l ! I'm able to use this.googleMaps.fitBounds as well as google-map-react/utils/fitBound just fine, what i'm asking is for the typings of google-map-react/utils/fitBound that is not related to this.googleMaps.fitBounds

The file is https://github.com/google-map-react/google-map-react/blob/master/src/utils/utils.js
and is documented here https://github.com/google-map-react/google-map-react/blob/master/API.md#utility-functions

@edgarjrg I would recommend you to use googleMaps.fitBounds, something like how I did it here in google-map-react-examples

Was this page helpful?
0 / 5 - 0 ratings

Related issues

junibrosas picture junibrosas  路  3Comments

arunshan picture arunshan  路  5Comments

VLNTNA picture VLNTNA  路  4Comments

figalex picture figalex  路  4Comments

edcolcode picture edcolcode  路  3Comments