Baidumap
Baidu Map(百度地图) API wrapper in Ruby
Installation
Add this line to your application's Gemfile:
gem 'baidu_map'
And then execute:
$ bundle
Or install it yourself as:
$ gem install baidumap
Usage
Initialize
Baidumap.ak = "aaaaaaaaaaaaaaaaaa"
# or
Baidumap.setup { @ak = "aaaaaaaaaaaaaaaaaa" }
Example
Please note that params shouldn't including output: 'json'
or output: 'xml'
, because which will be added by gem automatically and the result is always a hash.
# Place API
Baidumap.place_search(query: "九亭", region: "上海", scope: '1')
Baidumap.place_detail(uid: "5508504d0319eecac6f0259a", scope: '2')
Baidumap.place_detail(uids: "5508504d0319eecac6f0259a, 104274a315f7134fc3f1cfde", output: 'json', scope: '2') # NOTE and TODO: there is a bug that "," in uids's value will be translated, so this method is not usable currently.
# Place Suggestion API
Baidumap.place_suggestion(query: "九亭", region: "全国")
# Geocoding API
Baidumap.geocoder(address: "九亭")
Baidumap.geocoder(location: '121.33428124857, 31.13491723367') # NOTE and TODO: there is a bug that "," in uids's value will be translated, so this method is not usable currently.
# IP定位API
Baidumap.location(ip: "115.172.82.212", coor: "bd09ll")
Result Debug
If the result's return status from Baidu API is not "0", then there is an error. To debug it, you always can attatch a block { |debug| debug.inspect }
to show the original url requested from this gem to Baidu just like this:
Baidumap.place_detail(uids: [ "5508504d0319eecac6f0259a, 104274a315f7134fc3f1cfde" ], output: 'json', scope: '2') { |deug| debug.inspect }
You can show your ak value used by this gem through this code Baidumap.ak
.
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
to create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
- Fork it ( https://github.com/yanyingwang/baidumap/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request