Skip to content

Cannot read property 'fromLatLngToDivPixel' of undefined  #257

Closed

Description

@Bronsequences

Intermittently seeing Cannot read property 'fromLatLngToDivPixel' of undefined errors in production. Unable to successfully reproduce this locally.

Stack trace from Raygun:
screen shot 2016-10-17 at 6 03 29 pm
browsers affected

Implementation below: (using custom pointer component for styling only)

  renderMap() {
    const { location, googleMaps } = this.props;

    if (location.lat && location.lon) {
      return (
        <GoogleMap options={this.createMapOptions}
          defaultCenter={{lat: location.lat, lng: location.lon}}
          defaultZoom={16}
          bootstrapURLKeys={{key: googleMaps.apiKey, language: 'en'}}>
          <Pointer lat={location.lat} lng={location.lon} />
        </GoogleMap>
      );
    }

    return null;
  }

Activity

  1. reintroducing commented on Oct 28, 2016

    @reintroducing

    I saw this today too, locally, but just refreshed and it went away. It's definitely intermittent but I have no clue when/why it happens :\ Only happened to me once thus far.

  2. gabriel-laet commented on Nov 23, 2016

    @gabriel-laet

    Also noticing the same exception in production. I couldn't see a clear pattern between users, seems to affect all modern browsers as well.

  3. yuya373 commented on Dec 2, 2016

    @yuya373

    Hi! I have same exception. I got this.

    TypeError
    Cannot read property 'fromLatLngToDivPixel' of undefined
    /assets/sources/pc_app-41d9587d14747b5803601f7937d20217e68a31a68be1a1cbed079760151ca726.js in apply at line 98459:39
    	          var div = overlay.div;
    	          var overlayProjection = overlay.getProjection();
    	          var bounds = map.getBounds();
    	          var ne = bounds.getNorthEast();
    	          var sw = bounds.getSouthWest();
    	          var ptx = overlayProjection.fromLatLngToDivPixel(new maps.LatLng(ne.lat(), sw.lng()));
    	          // need round for safari still can't find what need for firefox
    	          var ptxRounded = (0, _detect2.default)().isSafari ? { x: Math.round(ptx.x), y: Math.round(ptx.y) } : { x: ptx.x, y: ptx.y };
    	          this_.updateCounter_++;
    	          this_._onBoundsChanged(map, maps);
    

    exception shows overlayProjection is undefined , so I read google maps reference and I found The projection is not initialized until onAdd is called by the API. in the document of getProjection() method of OverlayView instance.
    I think getProjection() is called before onAdd is excecuted, and then overlayProjection is undefined and then got Cannot read property 'fromLatLngToDivPixel' of undefined.

    Google Maps JavaScript API V3 Reference  |  Google Maps JavaScript API  |  Google Developers
    google-map-react/google_map.js at 7a9a8d3fb7f3d1bf4409bddd326f2cc0545857cc · istarkov/google-map-react

  4. sunkaflek commented on Dec 3, 2016

    @sunkaflek

    same issue here. Unfortunately no clear pattern, happens "sometimes"

  5. parth-vora-7 commented on Mar 29, 2017

    @parth-vora-7

    Hello,

    Same for me too. Not found any clear pattern yet for this error. Did anyone ever fixed that?

    Thanks

  6. parth-vora-7 commented on Mar 29, 2017

    @parth-vora-7

    Hello,

    I think I found the solution. Just use the latest version of the infobox.js:

    https://github.com/googlemaps/v3-utility-library/blob/master/infobox/src/infobox.js

    I was using version 1.0 before. After upgrading to the version 1.1.13, I'm not getting that error anymore.

    Hope this will help someone.

    Thanks

  7. mariusandra commented on Oct 3, 2017

    @mariusandra
    Contributor

    I'm also occasionally seeing this reported by Bugsnag, but can never reproduce locally. Has anyone find something that could help?

    I'm not sure I understand what InfoBox has to do with this?

  8. mariusandra commented on Oct 3, 2017

    @mariusandra
    Contributor

    I released a package called @mariusandra/google-map-react on NPM, which is google-map-react v0.24.0 plus a quick if (overlayProjection) hack in the hopes of fixing this bug.

    I'm not sure if it works, but putting this out there for the adventurous to try.

  9. nuclearspike commented on Feb 17, 2018

    @nuclearspike

    I'm also seeing this in production. Any plan to apply something like @mariusandra 's solution to master?

  10. added a commit that references this issue on Feb 19, 2018
  11. itsmichaeldiego commented on Feb 20, 2018

    @itsmichaeldiego
    Member

    @mariusandra You can totally create a PR and we'll merge it into our master, test it and release it 👍

    @nuclearspike ^

  12. Bronsequences commented on Mar 2, 2018

    @Bronsequences
    Author

    Thanks @itsmichaeldiego for releasing a fix for this.
    I'm upgrading to the 0.32.0 package now and as it's intermittent will report back as to whether it's fixed. We've seen 88 instances of this error logged in Raygun over the last week so I should know in a day or so.

  13. Bronsequences commented on Mar 5, 2018

    @Bronsequences
    Author

    Haven't seen any new instances of this error since updating to 0.32.0 so I'm calling it fixed and will close this issue now. Thanks again for taking the time to fix this for us. :)

  14. nuclearspike commented on Mar 5, 2018

    @nuclearspike

    Thanks for getting this out. Upgrading now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions