Class: Google::Geo::Address

Inherits:
Object
  • Object
show all
Includes:
Parser
Defined in:
lib/google/geo/address.rb,
lib/google/geo/address/street_view.rb

Overview

Represents locations returned in response to geocoding queries.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Parser

#fetch, #fetch_accuracy

Constructor Details

#initialize(placemark, query, geo) ⇒ Address

:nodoc



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/google/geo/address.rb', line 51

def initialize(placemark, query, geo) #:nodoc
  @geo   = geo
  @xml   = placemark
  @query = query

  { :@street       => :ThoroughfareName,
    :@city         => :LocalityName,
    :@zip          => :PostalCodeNumber,
    :@county       => :SubAdministrativeAreaName,
    :@state        => :AdministrativeAreaName,
    :@country      => :CountryNameCode,
    
    :@full_address => :address
  }.each do |attribute, element|
    instance_variable_set(attribute, (fetch(element) rescue nil))
  end
  
  @longitude, @latitude, @elevation = 
    @coordinates = fetch(:coordinates).split(",").map { |x| x.to_f }
  
  @accuracy = fetch_accuracy
end

Instance Attribute Details

#accuracyObject (readonly)

An integer, Google’s rating of the accuracy of the supplied address.



42
43
44
# File 'lib/google/geo/address.rb', line 42

def accuracy
  @accuracy
end

#cityObject (readonly) Also known as: locality

Returns the value of attribute city.



12
13
14
# File 'lib/google/geo/address.rb', line 12

def city
  @city
end

#coordinatesObject (readonly)

An array containing the standard three elements of a coordinate triple: latitude, longitude, elevation.



28
29
30
# File 'lib/google/geo/address.rb', line 28

def coordinates
  @coordinates
end

#countryObject (readonly) Also known as: country_code

Returns the value of attribute country.



24
25
26
# File 'lib/google/geo/address.rb', line 24

def country
  @country
end

#countyObject (readonly) Also known as: subadministrative_area

Returns the value of attribute county.



18
19
20
# File 'lib/google/geo/address.rb', line 18

def county
  @county
end

#elevationObject (readonly)

A float, the standard third element of a coordinate triple.



39
40
41
# File 'lib/google/geo/address.rb', line 39

def elevation
  @elevation
end

#full_addressObject (readonly) Also known as: to_s

All address attributes as one string, formatted by the service.



45
46
47
# File 'lib/google/geo/address.rb', line 45

def full_address
  @full_address
end

#latitudeObject (readonly) Also known as: lat

A float, the standard second element of a coordinate triple.



35
36
37
# File 'lib/google/geo/address.rb', line 35

def latitude
  @latitude
end

#longitudeObject (readonly) Also known as: lng

A float, the standard first element of a coordinate triple.



31
32
33
# File 'lib/google/geo/address.rb', line 31

def longitude
  @longitude
end

#queryObject (readonly)

The address query sent to the service. i.e. The user input.



49
50
51
# File 'lib/google/geo/address.rb', line 49

def query
  @query
end

#stateObject (readonly) Also known as: administrative_area

Returns the value of attribute state.



21
22
23
# File 'lib/google/geo/address.rb', line 21

def state
  @state
end

#streetObject (readonly) Also known as: thoroughfare

Returns the value of attribute street.



9
10
11
# File 'lib/google/geo/address.rb', line 9

def street
  @street
end

#zipObject (readonly) Also known as: postal_code

Returns the value of attribute zip.



15
16
17
# File 'lib/google/geo/address.rb', line 15

def zip
  @zip
end

Instance Method Details

#street_view_html(options = {}) ⇒ Object

This is a shady method which relies on an unofficial Google API. Use at your own risk!



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/google/geo/address/street_view.rb', line 8

def street_view_html(options = {})
%{<embed id="#{options[:id] or 'google-geo-streetview'}"
style="#{options[:style]}"
src="http://maps.google.com/mapfiles/cb/googlepano.066.swf"
quality="high" wmode="opaque" swliveconnect="false"
allowscriptaccess="always" type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer" 
scale="noscale" salign="lt"
flashvars="panoId=#{street_view_pano_id}&amp;directionMap=N:N,W:W,S:S,E:E,NW:NW,NE:NE,SW:SW,SE:SE&amp;yaw=0&amp;zoom=0&amp;browser=3&amp;pitch=5&amp;viewerId=1&amp;context=api&amp;animateOnLoad=false&amp;useSsl=false"
></embed>}.gsub("\n", "").squeeze(" ")
end