Skip to content

map.getProjection(...).fromContainerPixelToLatLng is not a function #1202

Description

@sohagmahin

I can't convert point to latlng.
Here is my code.

  function convertPointToLatLng(x, y) {
    // Function to convert screen coordinates to LatLng
    if (map.getProjection()) {
      const point = new maps.Point(x, y);
      const latLng = map.getProjection().fromContainerPixelToLatLng(point);
      return latLng;
    }
  }

Got an error like map.getProjection(...).fromContainerPixelToLatLng is not a function

Activity

  1. mustafairam commented on Feb 19, 2024

    @mustafairam

    same here. cannot use :

    const latLng = map.getProjection().fromContainerPixelToLatLng(point);

  2. besch commented on Apr 4, 2024

    @besch

    Me too

  3. kgrigor commented on Jun 3, 2024

    @kgrigor

    I think this is only available in the draw() function. Take a look at how InfoBox is using one of the functions returned from google.maps.MapCanvasProjection type getProjection() call.

  4. kgrigor commented on Jun 3, 2024

    @kgrigor

    Here's one way you can achieve this, which is a bit ugly, but works for me.

    const overlay = new google.maps.OverlayView();
    overlay.draw = function () {};
    overlay.setMap(map);
    const point = overlay.getProjection().fromLatLngToContainerPixel(point);
    

    then point will have the x,y pixel value with respect to the map.

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