|
SketchUp Ruby API Reference |
The LatLong class contains various methods for creating and manipulating latitude and longitude coordinates.
Parent: Object
Methods: new, latitude, longitude, to_a, to_s, to_utm
Example
Code: latlongtests.rb
The new method creates a LatLong object
latlong = Geom::LatLong.new(latlong)
latlong - a latitude and longitude coordinate set
latlong - a LatLong object
ll = [40.01700, 105.28300]
latlong = Geom::LatLong.new(ll)
if (latlong)
UI.messagebox latlong
else
UI.messagebox "Failure"
end
The Latitude method retrieves the latitude coordinate from a LatLong object.
latitude = latlong.latitude
latitude - a latitude coordinate value
coordinates = [10, 10, 10]
model = Sketchup.active_model
point = Geom::Point3d.new(coordinates)
latlong = model.point_to_latlong point
latitude = latlong.latitude
if (latitude)
UI.messagebox latitude
else
UI.messagebox "Failure"
end
The Latitude method retrieves the longitude coordinate from a LatLong object.
latitude = latlong.longitude
longitude - a latitude coordinate value
coordinates = [10, 10, 10]
model = Sketchup.active_model
point = Geom::Point3d.new(coordinates)
latlong = model.point_to_latlong point
longitude = latlong.longitude
if (longitude)
UI.messagebox longitude
else
UI.messagebox "Failure"
end
The to_a method converts a LatLong object to an array of two values.
array = latlong.to_a
array - an array of two values: latitude and longitude
coordinates = [10, 10, 10]
model = Sketchup.active_model
point = Geom::Point3d.new(coordinates)
latlong = model.point_to_latlong point
a = latlong.to_a
if (a)
UI.messagebox a
else
UI.messagebox "Failure"
end
The to_a method converts a LatLong object to a string.
string = latlong.to_s
string - a string representation of a LatLong object
coordinates = [10, 10, 10]
model = Sketchup.active_model
point = Geom::Point3d.new(coordinates)
latlong = model.point_to_latlong point
s = latlong.to_s
if (s)
UI.messagebox s
else
UI.messagebox "Failure"
end
The to_a method converts a LatLong object to a UTM object.
utm = latlong.to_utm
utm - a UTM object
coordinates = [10, 10, 10]
model = Sketchup.active_model
point = Geom::Point3d.new(coordinates)
latlong = model.point_to_latlong point
utm = latlong.to_utm
if (utm)
text = utm.to_s
UI.messagebox text
else
UI.messagebox "Failure"
end