位置接口,目前调用百度或者高德地理位置api获取格式化的地理位置数据.
添加以下代码到Gemfile:
gem 'geo_api', git: 'git@github.com:liuzelei/geo_api.git', tag: 'v1.0.0'
配置代码:
GeoApi.setup do |config| config.server = "http://api.map.baidu.com/geocoder/v2/" config.key = "" #地主api的key config.vendor = 'BAIDU|GAODE' end
GeoApi.LocationService.instance.get_location_from_string("中山公园上海")
GeoApi.LocationService.instance.get_location_from_coordinate(12.34, 56.78, "bd09ll")
地址的格式化结果是
databack["province"] = "上海市"
databack["city"] = "上海市"
databack["region"] = "浦东新区"
databack["detail"] = "灵岩路79弄-1号"
databack["latitude"] = "31.172419183453"
databack["longitude"] = "121.50055678999"
GeoApi::LocationService.instance.coord_to_baidu("121.4660492,31.2117575;121.4664967,31.2111130", "3", "5")