module GeoApi

Constants

VERSION

Public Class Methods

config() click to toggle source
# File lib/geo_api.rb, line 13
def config
  @config ||= Configuration.new
end
get_coordinate_from_string(location, city = nil) click to toggle source
# File lib/geo_api.rb, line 51
def get_coordinate_from_string(location, city = nil)
  proxy.get_coordinate_from_string(location, city = nil)
end
get_location_from_coordinate(longitude, latitude) click to toggle source
# File lib/geo_api.rb, line 47
def get_location_from_coordinate(longitude, latitude)
  proxy.get_location_from_coordinate(longitude, latitude)
end
get_location_from_string(location) click to toggle source
# File lib/geo_api.rb, line 25
def get_location_from_string(location)
  unless location.nil? || location.length == 0
    formated_address = location.split(/,|-|;|>|:|\+|\^/)
    databack = Hash.new
    databack["province"] = formated_address[0] if formated_address.length > 0
    databack["city"] = formated_address[1] if formated_address.length > 1
    databack["region"] = formated_address[2] if formated_address.length > 2
    databack["detail"] = formated_address[3] if formated_address.length > 3
    databack["latitude"] = ""
    databack["longitude"] = ""

    if ["重庆市", "上海市", "北京市", "天津市"].include?(databack["province"])
      databack["region"] = databack["city"]
      databack["city"] = databack["province"]
    end

    return databack
  else
    return nil
  end
end
get_proxy() click to toggle source
# File lib/geo_api.rb, line 55
def get_proxy
  case config.vendor
  when 'BAIDU'
    return GeoApi::Baidu.new(config)
  when 'GAODE'
    return GeoApi::Gaode.new(config)
  else
    raise '不支持的Vendor'
  end
end
logger() click to toggle source
# File lib/geo_api.rb, line 17
def logger
  @logger ||= Logger.new(STDOUT)
end
proxy() click to toggle source
# File lib/geo_api.rb, line 21
def proxy
  @proxy ||= get_proxy
end
setup() { |config| ... } click to toggle source
# File lib/geo_api.rb, line 9
def setup
  yield config
end