0.0
No commit activity in last 3 years
No release in over 3 years
Geocoder by Baidu Map
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.11
~> 2.0
~> 10.0
~> 3.0
 Project Readme

BaiduGeocoderGem Version

使用百度地图API进行地址定位坐标、坐标定位地址、名称定位地址。

安装

$ gem install baidu_geocoder

使用

调用

require 'baidu_geocoder'
include 'BaiduGeocoder'

## get_location_by_addr
loc = Geocoder.get_location_by_addr(addr)

## get_address_by_name
addr = Geocoder.get_address_by_name(name)

## get_address_by_loc
addr = Geocoder.get_address_by_loc(lat, lng)
  • tips: BaiduMapApi需要申请 MapAk. 为了避免因为ak限制问题,您也可以传入自己的ak(申请地址)
loc = Geocoder.get_location_by_addr(addr, your_ak)

命令行

➜  baidu_geocoder git:(master) ✗ baidu_geocoder
  Usage:
      baidu_geocoder -a addr    : 返回坐标
      baidu_geocoder -n name    : 返回地址
      baidu_geocoder -l lat lng : 返回地址
➜  baidu_geocoder git:(master) ✗ baidu_geocoder -n 北京市政府
获取地址成功:
{:province=>"北京市", :city=>"北京市", :district=>"西城区", :formatted_address=>"北京市西城区文津街"}

➜  baidu_geocoder git:(master) ✗ baidu_geocoder -a 北京市西城区文津街
获取定位成功:
{:lng=>116.39321980074757, :lat=>39.92881485241565}

➜  baidu_geocoder git:(master) ✗ baidu_geocoder -l 39.92881485241565 116.39321980074757
获取地址成功:
{:province=>"北京市", :city=>"北京市", :district=>"西城区", :formatted_address=>"北京市西城区文津街3号"}

License

The gem is available as open source under the terms of the MIT License.