高德地图根据ip精准定位

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sinat_15153911/article/details/82695796

高德地图根据ip精准定位

精准定位就是逆地理编码,将经纬度转换为详细结构化的地址信息。
例如:116.480881,39.989410 转换地址描述后:北京市朝阳区阜通东大街6号
但是我们首先要通过ip获取经纬度。而IP 地址(英语:IP Address),是分配给网络上使用网际协议(英语:Internet Protocol, IP)的设备的数字标签。暂时可以通过这个小工具https://www.v2ex.com/tools/ip来查询ip地址经纬度等信息。

这里写图片描述

//1、ip获取经纬度
String ip = "223.74.64.109";
        String url = "https://www.v2ex.com/tools/ip/"+ip;
        String title = "log,lat"; //经纬度
        String pat = "<tr>\r\n" + 
                "    <td>经度 Longitude</td>\r\n" + 
                "    <td>(.+?)</td>\r\n" + 
                "</tr><tr>\r\n" + 
                "    <td>维度 Latitude</td>\r\n" + 
                "    <td>(.+?)</td>\r\n" + 
                "</tr>";
        String encoding = "utf-8";
        List<String> list = getCode(url, title, pat, encoding);
        String location = list.toString().substring(1, list.toString().length()-1);
        //2、经纬度获取详细地址
        Map<String, String> code = _mapUtil.getGaodeAddress_2(location);
//      String address = code.getRegeocode().getFormatted_address();
//      String country = code.getRegeocode().getAddressComponent().getCountry();
//      String province = code.getRegeocode().getAddressComponent().getProvince();
//      String city = code.getRegeocode().getAddressComponent().getCity();
        System.out.println(code.get("address"));
        System.out.println(code.get("country"));
        System.out.println(code.get("province"));
        System.out.println(code.get("city"));

需获取源码,加QQ490647751,回复“开通VIP会员——高德地图根据ip精准定位”

猜你喜欢

转载自blog.csdn.net/sinat_15153911/article/details/82695796