Class: Baidu::Map
Class Method Summary collapse
-
.coordinate(poiname, cityid) ⇒ Object
从每条结果中解析x,y坐标.
-
.get_cityid(cityname) ⇒ Object
得到百度地图城市id.
Instance Method Summary collapse
- #around(lat, lng) ⇒ Object
- #bank ⇒ Object
- #bus ⇒ Object
- #cafe ⇒ Object
- #info ⇒ Object
-
#initialize(key) ⇒ Map
constructor
A new instance of Map.
- #spot ⇒ Object
- #within(radius) ⇒ Object
Constructor Details
#initialize(key) ⇒ Map
Returns a new instance of Map.
5 6 7 8 |
# File 'lib/baidu/map.rb', line 5 def initialize(key) @key = key @segments = {:ak=>@key,:output=>'json',:radius=>1000} end |
Class Method Details
.coordinate(poiname, cityid) ⇒ Object
从每条结果中解析x,y坐标
47 48 49 50 51 52 53 54 55 |
# File 'lib/baidu/map.rb', line 47 def self.coordinate(poiname,cityid) # puts "http://api.map.baidu.com/geocoder?address=#{URI.encode(poiname)}&output=json&key=#{@key}&city=#{URI.encode(cityid)}" url = "http://api.map.baidu.com/geocoder?address=#{URI.encode(poiname)}&output=json&key=#{@key}&city=#{cityid}" result = get url location = result['result'] return nil if location.nil? or location.empty? location = location['location'] return location['lng'],location['lat'] if result['status'] == 'OK' end |
.get_cityid(cityname) ⇒ Object
得到百度地图城市id
41 42 43 44 |
# File 'lib/baidu/map.rb', line 41 def self.get_cityid(cityname) body = get "http://api.map.baidu.com/?qt=cur&wd=#{URI.encode(cityname)}&ie=utf-8&res=api" return body['content']['code'] end |
Instance Method Details
#around(lat, lng) ⇒ Object
30 31 32 33 |
# File 'lib/baidu/map.rb', line 30 def around(lat,lng) @segments[:location] = "#{lat},#{lng}" self end |
#bank ⇒ Object
15 16 17 18 |
# File 'lib/baidu/map.rb', line 15 def bank @segments[:query]='银行' self end |
#bus ⇒ Object
10 11 12 13 |
# File 'lib/baidu/map.rb', line 10 def bus @segments[:query]='公交站' self end |
#cafe ⇒ Object
20 21 22 23 |
# File 'lib/baidu/map.rb', line 20 def cafe @segments[:query]='餐馆' self end |
#info ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/baidu/map.rb', line 57 def info uri = URI::HTTP.build( :host => 'api.map.baidu.com', :query=> URI.encode(@segments.map{|k,v|"#{k}=#{v}"}.join('&')), :path => '/place/v2/search' ) self.class.get(uri.to_s) end |
#spot ⇒ Object
25 26 27 28 |
# File 'lib/baidu/map.rb', line 25 def spot @segments[:query]='景点' self end |
#within(radius) ⇒ Object
35 36 37 38 |
# File 'lib/baidu/map.rb', line 35 def within(radius) @segments[:radius] = radius self end |