zoukankan      html  css  js  c++  java
  • 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("北京")); } }

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

  • 相关阅读:
    定时器的实现
    派遣函数
    IRP的同步
    duilib基本流程
    驱动程序的同步处理
    WFP在包含fwpmu.h头的时候出错
    自己写的驱动用CreateFile打开时错误码返回1的问题
    Windows内核函数
    16_会话技术_Session
    15_会话技术_Cookie
  • 原文地址:https://www.cnblogs.com/news1997/p/10906414.html
Copyright © 2011-2022 走看看