You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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.
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.
I can't convert point to latlng.
Here is my code.
Got an error like
map.getProjection(...).fromContainerPixelToLatLng is not a function
The text was updated successfully, but these errors were encountered: