• java实现根据高德地图API接口进行地址位置解析,将地址转化为经纬度


    原创文章,转载请注明,欢迎评论和更改。

    1,所需额外ar包,import net.sf.json.JSONObject;

    2,完整源代码代码

    package com.travel.util;
    
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.net.URL;
    import java.net.URLConnection;
    
    import net.sf.json.JSONObject;
        
    public class AddressLngLatExchange {
        
        public String getLngLat(String address) {
            StringBuffer json = new StringBuffer();
            try {
                URL u = new URL("http://restapi.amap.com/v3/geocode/geo?address="+address+"&output=JSON&key=7f4ffae4074e8b8e4d147190527a4b72");
                URLConnection yc = u.openConnection();
                //读取返回的数据
                BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream(),"UTF-8"));
                String inputline = null;
                while((inputline=in.readLine())!=null){
                    json.append(inputline);
                }
            in.close();
            } catch (Exception e) {
                 e.printStackTrace();
             }
            String jsonStr=json.toString();
            JSONObject jsonObject = JSONObject.fromObject(jsonStr);
            
         //判断输入的位置点是否存在
    if(jsonObject.getJSONArray("geocodes").size()>0) return jsonObject.getJSONArray("geocodes").getJSONObject(0).get("location").toString(); else return null; } public static void main(String[] args) { AddressLngLatExchange addressLngLatExchange=new AddressLngLatExchange(); System.out.println(addressLngLatExchange.getLngLat("北京")); } }

    原创文章,转载请注明,欢迎评论和更改。

  • 相关阅读:
    socket 常用api
    socket客户端小例
    select和ioctl的一个简单测试
    git 相关配置
    pvr转png
    flash 中matrix
    moto x使用注意事项
    互联网思维将颠覆我们的认知
    微信公众账号怎么快速增加粉丝
    Discuz如何解除某个会员的QQ绑定状态
  • 原文地址:https://www.cnblogs.com/news1997/p/10906414.html
Copyright © 2020-2023  润新知