坐标转换/Coordconver

Build Status

  • 1.提供了百度坐标(BD-09)、国测局坐标(火星坐标,GCJ-02)、和 地球坐标( WGS-84) 坐标系之间的转换。

  • 2.坐标点到经纬度的相互转换

  • 3.坐标点到地理位置的转换(TODO)

安装

添加到Gemfile:

gem 'coordconver'

执行:

$ bundle

或者只安装该GEM:

$ gem install coordconver

坐标系转换

用法

提供6转换方式,传入参数需为float类型,如:

Coordconver.bd_gcj(lng.to_f, lat.to_f)

坐标系 转换名称 方法
BD-09 -> GCJ-02 百度 -> 谷歌、高德 Coordconver.bd_gcj(lng, lat)
BD-09 -> WGS-84 百度 -> 地球坐标 Coordconver.bd_wgs(lng, lat)
GCJ-02 -> WGS-84 谷歌、高德 -> 地球坐标 Coordconver.gcj_wgs(lng, lat)
GCJ-02 -> BD-09 谷歌、高德 -> 百度 Coordconver.gcj_bd(lng, lat)
WGS-84 -> BD-09 地球坐标 -> 百度 Coordconver.wgs_bd(lng, lat)
WGS-84 -> GCJ-02 地球坐标 -> 谷歌、高德 Coordconver.wgs_gcj(lng, lat)

示例:

Coordconver.wgs_bd(121.46873833333332, 31.247138333333336) # => [121.479808223763, 31.25115814844421]

坐标系说明

百度坐标系 (BD-09)

  • 百度标准,百度 SDK,百度地图,Geocoding 使用

火星坐标系 (GCJ-02)

  • 中国标准(国测局坐标系),从国行移动设备中定位获取的坐标数据使用这个坐标系, 由中国国家测绘局制订的地理信息系统的坐标系统

  • 由WGS84坐标系经加密后的坐标系

  • 谷歌中国地图, 搜搜中国地图, iOS地图(高德), 搜搜, 阿里云, 高德地图, 腾讯

地球坐标系 (WGS-84)

  • 国际标准, 设备一般包含GPS芯片或者北斗芯片获取的经纬度为WGS84地理坐标系

  • 谷歌地图采用的是WGS84地理坐标系(中国范围除外)

  • ios的原生定位库, osm

相关资料

坐标点与经纬度转换

用法

提供4种转换方式,传入坐标点需为float类型,传入经纬度需为string类型。

转换名称 方法
坐标点转度数 Coordconver.degree(lng, lat)
单个坐标点转度数 Coordconver.cal_degree(n)
度数点转坐标点 Coordconver.undegree(lng_degree, lat_degree)
单个度数转坐标点 Coordconver.cal_degree(n)

示例:

Coordconver.degree(38.65777, 104.08296) # => ["38°39′27″","104°4′58″"]

Coordconver.undegree("38°39′27.97″","104°4′58.66″") # => [38.65777,104.08296]

相关资料

    

坐标点与地址转换(TODO)

1.百度地图转换

2.高德地图转换

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also 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, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/cheenwe/coordconver.

License

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