3

In google maps v3 api, How do I convert the point and zoom that get passed to ImageMapTypeOptions.getTitleUrl to a LatLng?

Thanks!

Drew LeSueur
  • 19,185
  • 29
  • 89
  • 106

2 Answers2

1

This shows how it's done with code you can reimplement in other languages.

https://developers.google.com/maps/documentation/javascript/examples/map-coordinates

Drew LeSueur
  • 19,185
  • 29
  • 89
  • 106
0
    const TILE_SIZE = 314;

    const tileCoordToWorldCoord = ( tileCoord, zoom ) => {
        const scale = Math.pow( 2, zoom );
        const shift = Math.floor( TILE_SIZE / 2 );
        const calc = tc => ( tc * TILE_SIZE + shift ) / scale;

        const x = calc( tileCoord.x );
        const y = calc( tileCoord.y );
        return new google.maps.Point( x, y );
    }

    ...

        getTileUrl: ( coord, zoom ) => {
            const pointCoord = tileCoordToWorldCoord( coord, zoom );
            const latLng = mapInstance.getProjection().fromPointToLatLng( pointCoord );
        }
Anton Duzenko
  • 2,366
  • 1
  • 21
  • 26