Class: GoogleMaps::Services::StreetViewImage

Inherits:
Object
  • Object
show all
Defined in:
lib/googlemaps/services/streetview.rb

Overview

Performs requests to the Google Street View Map API.

Examples:

Get the street view map image

streetview = GoogleMaps::Services::StreetViewImage.new(client)
map_img = streetview.query(size: {:length=>400, :width=>400}, location: "40.714728,-73.998672", heading: 151.78, pitch: -0.76)
# {
#   :url => "https://maps.googleapis.com/maps/api/streetview?size=400x400&location=40.714728%2C-73.998672&heading=151.78&pitch=-0.76",
#   :mime_type => "image/jpeg",
#   :image_data => "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHR..."
# }

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ StreetViewImage

Returns a new instance of StreetViewImage.

Since:

  • 1.0.0



21
22
23
# File 'lib/googlemaps/services/streetview.rb', line 21

def initialize(client)
  self.client = client
end

Instance Attribute Details

#clientSymbol

Returns The HTTP client.

Returns:

  • (Symbol)

    The HTTP client.

Since:

  • 1.0.0



19
20
21
# File 'lib/googlemaps/services/streetview.rb', line 19

def client
  @client
end

Instance Method Details

#query(size:, location: nil, pano: nil, heading: nil, fov: nil, pitch: nil) ⇒ Hash

Get the street view map image.

Parameters:

  • size (Hash)

    the rectangular dimensions of the street view image.

  • location (String, Hash) (defaults to: nil)

    The address or lat/lng value of the street view map.

  • pano (String) (defaults to: nil)

    A specific panorama ID.

  • heading (Numeric) (defaults to: nil)

    The compass heading of the camera. Accepted values are from 0 to 360.

  • fov (Numeric) (defaults to: nil)

    The horizontal field of view of the image. It is expressed in degrees, with a maximum allowed value of 120.

  • pitch (Numeric) (defaults to: nil)

    The up or down angle of the camera relative to the Street View vehicle. Positive values angle the camera up (with 90 degrees indicating straight up). Negative values angle the camera down (with -90 indicating straight down).

Returns:

  • (Hash)

    Hash with image URL, MIME type and its base64-encoded value.

Since:

  • 1.0.0



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/googlemaps/services/streetview.rb', line 37

def query(size:, location: nil, pano: nil, heading: nil, fov: nil, pitch: nil)
  params = {
    'size' => Convert.rectangular_dimensions(size)
  }

  if location
    params['location'] = Convert.to_latlng(location)
  end

  if pano
    params['pano'] = pano
  end

  if location && pano
    raise StandardError, 'should not specify both location and panorama ID.'
  end

  if heading
    raise StandardError, 'invalid compass heading value.' unless (0..360).include? heading
    params['heading'] = heading
  end

  if fov
    raise StandardError, 'invalid field of view (fov) value.' unless (0..120).include? fov
    params['fov'] = fov
  end

  if pitch
    raise StandardError, 'invalid pitch value.' unless (-90..90).include? pitch
    params['pitch'] = pitch
  end

  self.client.request(url: "/maps/api/streetview", params: params)
end