1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > 百度地图api-全球逆地理编码

百度地图api-全球逆地理编码

时间:2020-12-03 10:24:36

相关推荐

百度地图api-全球逆地理编码

全球逆地理编码服务(又名Geocoder)是一类Web API接口服务;

逆地理编码服务提供将坐标点(经纬度)转换为对应位置信息(如所在行政区划,周边地标点分布)功能。

服务同时支持全球行政区划位置描述及周边地标POI数据召回(包括中国在内的全球200多个国家地区);

若需访问境外POI,需申请「逆地理编码境外POI」服务权限,请申请开通境外服务权限。

用户可通过该功能,将位置坐标解析成对应的行政区划数据以及周边高权重地标地点分布情况,整体描述坐标所在的位置。

附:百度api官方文档地址:/index.php?title=webapi/guide/webservice-geocoding-abroad

接口:http://api./geocoder/v2/?callback=renderReverse&location=35.658651,139.745415&output=json&pois=1&latest_admin=1&ak=您的ak //GET请求

注:老版本行政区划数据已不再维护,为确保您的行政区划数据正确,请务必将latest_admin设置为1

接口传参和返回数据接口含义请查看官网文档描述,在这就不做介绍了。

/*** -逆地理编码—百度接口根据经纬度解析地址** @param lat_lng* @return* @throws IOException*/public static Map<String, String> geocoder(String lat_lng) throws IOException {URL url = new URL("http://api./geocoder/v2/?callback=renderReverse&language=zh-CN&location="+ lat_lng + "&output=json&pois=1&ak=你的ak");URLConnection connection = url.openConnection();/*** 然后把连接设为输出模式。URLConnection通常作为输入来使用,比如下载一个Web页。* 通过把URLConnection设为输出,你可以把数据向你个Web页传送。下面是如何做:*/connection.setDoOutput(true);OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "utf-8");out.flush();out.close();// 一旦发送成功,用以下方法就可以得到服务器的回应:String res;InputStream l_urlStream;l_urlStream = connection.getInputStream();BufferedReader in = new BufferedReader(new InputStreamReader(l_urlStream, "UTF-8"));StringBuilder sb = new StringBuilder("");while ((res = in.readLine()) != null) {sb.append(res.trim());}String str = sb.toString();Map<String, String> map = new HashMap<String, String>();if (str != null && str != "") {int addss = str.indexOf("country\":");int added = str.indexOf("\",\"country_code");if (addss > 0 && added > 0) {String country = str.substring(addss + 10, added);System.out.println("国家:" + country);map.put("country", country);}int addss1 = str.indexOf("province\":");int added1 = str.indexOf("\",\"city");if (addss1 > 0 && added1 > 0) {String province = str.substring(addss1 + 11, added1);System.out.println("州市:" + province);map.put("province", province);}int addss2 = str.indexOf("city\":");int added2 = str.indexOf("\",\"city_level");if (addss2 > 0 && added2 > 0) {String city = str.substring(addss2 + 7, added2);System.out.println("城市:" + city);map.put("city", city);}return map;}return null;

下面进行接口的测试:

public static void main(String[] args) throws IOException {Map map = testPost("48.845289,2.392104");System.out.println(map);}

输出结果

{"status":0,"result":{"location":{"lng":2.392103999999888,"lat":48.845289591136705},"formatted_address":"25 Rue du Sergent Bauchat, Paris, Ile-de-France, France","business":"","addressComponent":{"country":"France","country_code":49841,"country_code_iso":"FRA","country_code_iso2":"FR","province":"Ile-de-France","city":"Paris","city_level":2,"district":"","town":"","adcode":"0","street":"Rue du Sergent Bauchat","street_number":"25","direction":"附近","distance":"10"},"pois":[],"roads":[],"poiRegions":[],"sematic_description":"","cityCode":49872}}

国家:France

州市:Ile-de-France

城市:Paris

{country=France, province=Ile-de-France, city=Paris}

可以通过百度地图拾取坐标系统 http://api./lbsapi/getpoint/index.html查看输入的经纬度地点信息

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。