script/street2coordinates.rb
# Does the actual conversion of the US address string into coordinates
Does the actual conversion of the US address string into coordinates
Does the actual conversion of the US address string into coordinates
def geocode_us_address(address)
  country_names = '(U\.?S\.?A?\.?|United States|America)'
  country_names_suffix_re = Regexp.new(S2C_WHITESPACE+country_names+S2C_WHITESPACE+'?$', Regexp::IGNORECASE)
  countryless_address = address.gsub(country_names_suffix_re, '')
  locations = $geocoder_db.geocode(countryless_address)
  if locations and locations.length>0
    location = locations[0]
    if location[:number] and location[:street]
      street_address = location[:number]+' '+location[:street]
    else
      street_address = ''
    end
    info = {
      :latitude => location[:lat],
      :longitude => location[:lon],
      :country_code => 'US',
      :country_code3 => 'USA',
      :country_name => 'United States',
      :region => location[:state],
      :locality => location[:city],
      :street_address => street_address,
      :street_number => location[:number],
      :street_name => location[:street],
      :confidence => location[:score],
      :fips_county => location[:fips_county]
    }
  else
    info = nil
  end
  info
end
def geocode_us_address ( address ) country_names = '(U\.?S\.?A?\.?|United States|America)' country_names_suffix_re = Regexp . new ( S2C_WHITESPACE + country_names + S2C_WHITESPACE + '?$' , Regexp :: IGNORECASE ) countryless_address = address . gsub ( country_names_suffix_re , '' ) locations = $geocoder_db . geocode ( countryless_address ) if locations and locations . length > 0 location = locations [ 0 ] if location [ :number ] and location [ :street ] street_address = location [ :number ] + ' ' + location [ :street ] else street_address = '' end info = { :latitude => location [ :lat ] , :longitude => location [ :lon ] , :country_code => 'US' , :country_code3 => 'USA' , :country_name => 'United States' , :region => location [ :state ] , :locality => location [ :city ] , :street_address => street_address , :street_number => location [ :number ] , :street_name => location [ :street ] , :confidence => location [ :score ] , :fips_county => location [ :fips_county ] } else info = nil end info end
Does the actual conversion of the US address string into coordinates
Does the actual conversion of the US address string into coordinates
address