You are here

public function AddressToGeo::calcZoom in Geolocation Address Link 8

A method to roughly calculate the right zoom level for a place.

Uses the boundary information and an assumption about the pixel width that the map will be displayed at.

Parameters

array $boundary: An array of boundary values as returned by Google's geocoding service.

integer $pixel_width: The estimated pixel width of the map display.

Return value

integer $zoom A zoom level that will display everything in the boundary box.

See also

https://stackoverflow.com/questions/6048975/google-maps-v3-how-to-calcul...

File

src/AddressToGeo.php, line 242

Class

AddressToGeo
Class AddressToGeo.

Namespace

Drupal\geolocation_address_link

Code

public function calcZoom($boundary, $pixel_width = 800) {
  $globe_width = 256;

  // a constant in Google's map projection
  $west = $boundary['lng_south_west'];
  $east = $boundary['lng_north_east'];
  $angle = $east - $west;
  if ($angle < 0) {
    $angle += 360;
  }
  $zoom = round(log($pixel_width * 360 / $angle / $globe_width) / log(2));
  return $zoom;
}