Last active
          December 8, 2023 16:17 
        
      - 
      
- 
        Save bewithdhanu/5d732c4a923d3105b29d1ad99e9f1459 to your computer and use it in GitHub Desktop. 
    Google Map JS SDK - Convert window coordinates to LatLng
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | let x = 100; //relative left position of the point | |
| let y = 200; //relative top position of the point | |
| let projection = map.getProjection(); | |
| let scale = Math.pow(2, map.getZoom()); | |
| let topRight = projection.fromLatLngToPoint(map.getBounds().getNorthEast()); | |
| let bottomLeft = projection.fromLatLngToPoint(map.getBounds().getSouthWest()); | |
| const reversePoint = new google.maps.Point( | |
| bottomLeft.x + (x / scale), | |
| topRight.y + (y / scale) | |
| ); | |
| return projection.fromPointToLatLng(reversePoint); // converted value of x, y to LatLng | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment