React-google-maps: Accessing `google.maps` when Using withScriptjs

Created on 9 Aug 2017  路  2Comments  路  Source: tomchentw/react-google-maps

Currently, you can only access the google.maps reference when you statically reference the Google Maps API (by add the <script src="https://maps.googleapis.com/maps/api/js"></script> to your HTML). However, my application is isomorphic, in order to avoid loading the Google Maps API multiple times, I needed to load it asynchronously- so I opted to loading my API Key via withScriptjs.

Is there a way to access google.maps when loading the Google Maps API asynchronously.
This will be useful for using functions not defined in the package, such as the LatLngBounds method that I am trying to access.

(I need this to try out the solution for centering the map around markers:
https://gist.github.com/dyyylan/a086ed46670efccace96404c8ab97ad8
related to- https://github.com/tomchentw/react-google-maps/issues/260)

Most helpful comment

The solution that I found was that you can access google.maps through the window:
window.google.maps
All the Google methods can be accessed through this.

All 2 comments

The solution that I found was that you can access google.maps through the window:
window.google.maps
All the Google methods can be accessed through this.

I think window.google.maps and google.maps are actually referring to the same thing. They both resolved to the global (window) space. There's no difference using them.

You just need to defer the initialization step after withScriptjs has rendered it's wrapped component.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

0x1bitcrack3r picture 0x1bitcrack3r  路  3Comments

manoj150283 picture manoj150283  路  3Comments

ShintaroNippon picture ShintaroNippon  路  3Comments

bansalvks picture bansalvks  路  3Comments

craigcartmell picture craigcartmell  路  4Comments