Class: Mapstatic::Conversion

Inherits:
Object
  • Object
show all
Defined in:
lib/mapstatic/conversion.rb

Instance Method Summary collapse

Instance Method Details

#lat_to_y(lat, zoom) ⇒ Object



15
16
17
18
19
# File 'lib/mapstatic/conversion.rb', line 15

def lat_to_y(lat, zoom)
  n = 2 ** zoom
  lat_rad = (lat / 180) * Math::PI
  (1 - Math.log( Math.tan(lat_rad) + (1 / Math.cos(lat_rad)) ) / Math::PI) / 2 * n
end

#lng_to_x(lng, zoom) ⇒ Object



5
6
7
8
# File 'lib/mapstatic/conversion.rb', line 5

def lng_to_x(lng, zoom)
  n = 2 ** zoom
  ((lng.to_f + 180) / 360) * n
end

#x_to_lng(x, zoom) ⇒ Object



10
11
12
13
# File 'lib/mapstatic/conversion.rb', line 10

def x_to_lng(x, zoom)
  n = 2.0 ** zoom
  lon_deg = x / n * 360.0 - 180.0
end

#y_to_lat(y, zoom) ⇒ Object



21
22
23
24
25
# File 'lib/mapstatic/conversion.rb', line 21

def y_to_lat(y, zoom)
  n = 2.0 ** zoom
  lat_rad = Math.atan(Math.sinh(Math::PI * (1 - 2 * y / n)))
  lat_deg = lat_rad / (Math::PI / 180.0)
end