Module: GeoApi

Defined in:
lib/geo_api.rb,
lib/geo_api/baidu.rb,
lib/geo_api/gaode.rb,
lib/geo_api/version.rb,
lib/geo_api/configuration.rb,
lib/generators/geo_api/install_generator.rb

Defined Under Namespace

Classes: Baidu, Configuration, Gaode, InstallGenerator

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.configObject



13
14
15
# File 'lib/geo_api.rb', line 13

def config
  @config ||= Configuration.new
end

.get_coordinate_from_string(location, city = nil) ⇒ Object



51
52
53
# 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) ⇒ Object



47
48
49
# 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) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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_proxyObject



55
56
57
58
59
60
61
62
63
64
# 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

.loggerObject



17
18
19
# File 'lib/geo_api.rb', line 17

def logger
  @logger ||= Logger.new(STDOUT)
end

.proxyObject



21
22
23
# File 'lib/geo_api.rb', line 21

def proxy
  @proxy ||= get_proxy
end

.setup {|config| ... } ⇒ Object

Yields:



9
10
11
# File 'lib/geo_api.rb', line 9

def setup
  yield config
end