本人在本地可以测试通过 ,但是部署到本人的公网服务器就报错
错误消息大致是 无法识别的主机 api.map.baidu.com
获取经纬度代码如下:
错误消息大致是 无法识别的主机 api.map.baidu.com
获取经纬度代码如下:
URL url = null; System.out.println("坐标地址==========>" + address); try { address = URLEncoder.encode(address, "UTF-8"); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); }//对url中的汉字进行转码 StringBuffer buffer = new StringBuffer(); String result_info = null; //结果信息 try { url = new URL("http://api.map.baidu.com/geocoder/v2/?ak=5c308cc0b5778382a04786719b815886&callback=renderOption&output=json&address="+address ); System.out.println("坐标地址=========111=>" + address); BufferedReader bufferedReader = null; bufferedReader = new BufferedReader(new InputStreamReader( url.openStream())); while ((result_info = bufferedReader.readLine())!= null) { buffer.append(result_info); } } catch (Exception e) { e.printStackTrace(); } result_info = buffer.toString(); Result res = null; String point = null; int index = result_info.indexOf("status")+8; if(result_info.substring(index, index+1).equals("0")){ result_info = result_info.substring(result_info.indexOf("(")+1, result_info.lastIndexOf(")")); JSONObject jsonobject = JSONObject.fromObject(result_info); res = (Result)JSONObject.toBean(jsonobject, Result.class); point = res.getResult().getLocation().getLng() + "|" + res.getResult().getLocation().getLat(); }else{ point="地名有误!"; }
大家看看是怎么回事,
解决方案