A couple of fixes to make the library comply with the different attribute names
possible on the bounds element. Formerly, a bounds element with a minlat or minLat attribute (instead of min_lat) would not be properly parsed. Now all three styles of attribute name are accepted.
This commit is contained in:
		
							parent
							
								
									48053d44c4
								
							
						
					
					
						commit
						931a10cd17
					
				| @ -45,10 +45,10 @@ module GPX | ||||
| 
 | ||||
|       def to_xml | ||||
|          bnd = REXML::Element.new('bounds') | ||||
|          bnd.attributes['min_lat'] = min_lat | ||||
|          bnd.attributes['min_lon'] = min_lon | ||||
|          bnd.attributes['max_lat'] = max_lat | ||||
|          bnd.attributes['max_lon'] = max_lon | ||||
|          bnd.attributes['minlat'] = min_lat | ||||
|          bnd.attributes['minlon'] = min_lon | ||||
|          bnd.attributes['maxlat'] = max_lat | ||||
|          bnd.attributes['maxlon'] = max_lon | ||||
|          bnd | ||||
|       end | ||||
| 
 | ||||
|  | ||||
| @ -53,10 +53,10 @@ module GPX | ||||
| 
 | ||||
|             bounds_element = (XPath.match(@xml, "/gpx/metadata/bounds").first rescue nil) | ||||
|             if bounds_element | ||||
|                @bounds.min_lat = bounds_element.attributes["min_lat"].to_f | ||||
|                @bounds.min_lon = bounds_element.attributes["min_lon"].to_f | ||||
|                @bounds.max_lat = bounds_element.attributes["max_lat"].to_f | ||||
|                @bounds.max_lon = bounds_element.attributes["max_lon"].to_f | ||||
|                @bounds.min_lat = get_bounds_attr_value(bounds_element, %w{ min_lat minlat minLat }) | ||||
|                @bounds.min_lon = get_bounds_attr_value(bounds_element, %w{ min_lon minlon minLon}) | ||||
|                @bounds.max_lat = get_bounds_attr_value(bounds_element, %w{ max_lat maxlat maxLat}) | ||||
|                @bounds.max_lon = get_bounds_attr_value(bounds_element, %w{ max_lon maxlon maxLon}) | ||||
|             else | ||||
|                get_bounds = true | ||||
|             end | ||||
| @ -82,6 +82,15 @@ module GPX | ||||
|          end | ||||
|       end | ||||
| 
 | ||||
|       def get_bounds_attr_value(el, possible_names) | ||||
|          result = nil | ||||
|          possible_names.each do |name| | ||||
|             result = el.attributes[name] | ||||
|             break unless result.nil? | ||||
|          end | ||||
|          return (result.to_f rescue nil) | ||||
|       end | ||||
| 
 | ||||
|       # Returns the distance, in kilometers, meters, or miles, of all of the | ||||
|       # tracks and segments contained in this GPXFile. | ||||
|       def distance(opts = { :units => 'kilometers' }) | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Doug Fales
						Doug Fales