models/student.rb
# Looks up the GPS coordinates of a location
#
# @param [String] location A string describing the location (for example, an
#   address, zip code, or city name)
# @return [Array<(Float, Float)>] The latitude and longitude of the location
#
# @todo Handle errors gracefully (malformed data, api being down, etc.)
# @todo Blindly using the first coordinates found might be a bad idea?
Looks up the GPS coordinates of a location
Looks up the GPS coordinates of a location
def geocode(location)
    sanitized_location = URI.escape(location)
    api_uri = URI.parse("http://nominatim.openstreetmap.org/search/#{sanitized_location}?format=json")
    city_data = JSON.parse(Net::HTTP.get(api_uri)).first
    latitude  = city_data['lat'].to_f
    longitude = city_data['lon'].to_f
    return [latitude, longitude]
  end
def geocode ( location ) sanitized_location = URI . escape ( location ) api_uri = URI . parse ( "http://nominatim.openstreetmap.org/search/#{sanitized_location}?format=json" ) city_data = JSON . parse ( Net :: HTTP . get ( api_uri ) ) . first latitude = city_data [ 'lat' ] . to_f longitude = city_data [ 'lon' ] . to_f return [ latitude , longitude ] end
Looks up the GPS coordinates of a location
Looks up the GPS coordinates of a location
The latitude and longitude of the location
The latitude and longitude of the location
Array<(Float, Float)>
location
location A string describing the location (for example, an address, zip code, or city name)
location A string describing the location ( for example an address zip code or city name )
todo
Handle errors gracefully (malformed data, api being down, etc.)
Handle errors gracefully ( malformed data api being down etc . )
todo
None