Class: GoogleMapsPlatform::DirectionsPolyline
- Inherits:
-
BaseModel
- Object
- CoreLibrary::BaseModel
- BaseModel
- GoogleMapsPlatform::DirectionsPolyline
- Defined in:
- lib/google_maps_platform/models/directions_polyline.rb
Overview
[Polyline encoding](developers.google.com/maps/documentation/utilities/polylin ealgorithm) is a lossy compression algorithm that allows you to store a series of coordinates as a single string. Point coordinates are encoded using signed values. If you only have a few static points, you may also wish to use the interactive polyline encoding utility. The encoding process converts a binary value into a series of character codes for ASCII characters using the familiar base64 encoding scheme: to ensure proper display of these characters, encoded values are summed with 63 (the ASCII character ‘?’) before converting them into ASCII. The algorithm also checks for additional character codes for a given point by checking the least significant bit of each byte group; if this bit is set to 1, the point is not yet fully formed and additional data must follow. Additionally, to conserve space, points only include the offset from the previous point (except of course for the first point). All points are encoded in Base64 as signed integers, as latitudes and longitudes are signed values. The encoding format within a polyline needs to represent two coordinates representing latitude and longitude to a reasonable precision. Given a maximum longitude of +/- 180 degrees to a precision of 5 decimal places (180.00000 to -180.00000), this results in the need for a 32 bit signed binary integer value.
Instance Attribute Summary collapse
-
#points ⇒ String
A single string representation of the polyline.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
-
.nullables ⇒ Object
An array for nullable fields.
-
.optionals ⇒ Object
An array for optional fields.
Instance Method Summary collapse
-
#initialize(points:, additional_properties: nil) ⇒ DirectionsPolyline
constructor
A new instance of DirectionsPolyline.
-
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
-
#to_s ⇒ Object
Provides a human-readable string representation of the object.
Methods inherited from BaseModel
#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json
Constructor Details
#initialize(points:, additional_properties: nil) ⇒ DirectionsPolyline
Returns a new instance of DirectionsPolyline.
53 54 55 56 57 58 59 |
# File 'lib/google_maps_platform/models/directions_polyline.rb', line 53 def initialize(points:, additional_properties: nil) # Add additional model properties to the instance additional_properties = {} if additional_properties.nil? @points = points @additional_properties = additional_properties end |
Instance Attribute Details
#points ⇒ String
A single string representation of the polyline.
34 35 36 |
# File 'lib/google_maps_platform/models/directions_polyline.rb', line 34 def points @points end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/google_maps_platform/models/directions_polyline.rb', line 62 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. points = hash.key?('points') ? hash['points'] : nil # Create a new hash for additional properties, removing known properties. new_hash = hash.reject { |k, _| names.value?(k) } additional_properties = APIHelper.get_additional_properties( new_hash, proc { |value| value } ) # Create object from extracted values. DirectionsPolyline.new(points: points, additional_properties: additional_properties) end |
.names ⇒ Object
A mapping from model property names to API property names.
37 38 39 40 41 |
# File 'lib/google_maps_platform/models/directions_polyline.rb', line 37 def self.names @_hash = {} if @_hash.nil? @_hash['points'] = 'points' @_hash end |
.nullables ⇒ Object
An array for nullable fields
49 50 51 |
# File 'lib/google_maps_platform/models/directions_polyline.rb', line 49 def self.nullables [] end |
.optionals ⇒ Object
An array for optional fields
44 45 46 |
# File 'lib/google_maps_platform/models/directions_polyline.rb', line 44 def self.optionals [] end |
Instance Method Details
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
87 88 89 90 91 |
# File 'lib/google_maps_platform/models/directions_polyline.rb', line 87 def inspect class_name = self.class.name.split('::').last "<#{class_name} points: #{@points.inspect}, additional_properties:"\ " #{@additional_properties}>" end |
#to_s ⇒ Object
Provides a human-readable string representation of the object.
81 82 83 84 |
# File 'lib/google_maps_platform/models/directions_polyline.rb', line 81 def to_s class_name = self.class.name.split('::').last "<#{class_name} points: #{@points}, additional_properties: #{@additional_properties}>" end |