Skip to content

Instantly share code, notes, and snippets.

@helloncanella
Created April 29, 2017 20:39
Show Gist options
  • Select an option

  • Save helloncanella/ee591fca78f667bac6f71acdc058f620 to your computer and use it in GitHub Desktop.

Select an option

Save helloncanella/ee591fca78f667bac6f71acdc058f620 to your computer and use it in GitHub Desktop.
Converting geolocation to pixel in the aps api
geolocationToPixel({ lat, lng }) {
const bounds = this.map.getBounds()
const geolocation = new google.maps.LatLng({ lat, lng })
, topRight = this.map.getProjection().fromLatLngToPoint(bounds.getNorthEast())
, bottomLeft = this.map.getProjection().fromLatLngToPoint(bounds.getSouthWest())
, scale = Math.pow(2, this.map.getZoom())
, worldPoint = this.map.getProjection().fromLatLngToPoint(geolocation)
return new google.maps.Point((worldPoint.x - bottomLeft.x) * scale, (worldPoint.y - topRight.y) * scale)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment