zoukankan      html  css  js  c++  java
  • 周边信息查询

    到了一个较陌生的环境,经常会在周边找一些基础设施,比如银行,商场,餐厅等(还有一种更急切的是找厕所)。通过百度提供的地图API,可以在你的应用中简单做到,详情可阅读Place API。我们以查找周边银行作为示例,需确定的参数至少有三个,要查找的位置的经度和纬度,需要查找的内容的类型或是关键字。
        public String getPalace(String query,String lat,String lng) throws ClientProtocolException, IOException{
            HttpClient httpClient 
    = new DefaultHttpClient();
            String url 
    = palceRequestUrl(query,lat,lng);
            logger.log(Level.INFO, url);
            HttpGet httpget 
    = new HttpGet(url);
            ResponseHandler
    <String> responseHandler = new BasicResponseHandler();
            String responseBody 
    = httpClient.execute(httpget, responseHandler);//位置xml
            logger.log(Level.INFO,"baidu response:"+responseBody);
            
    return responseBody;
        }
        
        
    public String palceRequestUrl(String query,String lat,String lng) throws UnsupportedEncodingException {
            String url 
    = WeChatConstant.BASEURL + "place/search?query=" + URLEncoder.encode(query,"UTF-8"+ "&key="
                    
    + WeChatConstant.MAPKEY +"&location="+lat+","+lng +"&radius=2000"+"&output=" + WeChatConstant.OUTPUTFORMAT;
            
    return url;
        }
    Junit测试
        @Test
        
    public void testGetBaiduPlace() throws Exception{
            BaiduMapService bms 
    = new BaiduMapService();
            String response 
    = bms.getPalace("银行""39.915""116.404");
            List
    <BaiduPlaceResponse> list = BaiduPlaceResponse.getBaiduPlace(response);
            
    for(BaiduPlaceResponse res:list){
                System.out.println(res.toString());
            }
        }
    输出内容(省略部分内容)
    <?xml version="1.0" encoding="utf-8" ?>
    <PlaceSearchResponse>
    <status>OK</status>
    <results>
    <result>
    <name>中国工商银行东长安街支行</name>
    <location>
    <lat>39.915891</lat>
    <lng>116.41867</lng>
    </location>
    <address>东城区东长安街1号东方广场西三办公楼1楼</address>
    <uid>a025683c73033c35a21de987</uid>
    <detail_url>http://api.map.baidu.com/place/detail?uid=a025683c73033c35a21de987&amp;amp;output=html&amp;amp;source=placeapi</detail_url>
    <tag>银行,王府井/东单</tag>
    </result>
    </results>
    </PlaceSearchResponse>
    BaiduPlaceResponse [name= 中国工商银行东长安街支行, telephone=null, address=东城区东长安街1号东方广场西三办公楼1 楼, lat=39.915891, lng=116.41867, tag=null, detailUrl=http://api.map.baidu.com/place/detail?uid=a025683c73033c35a21de987
    &amp;output=html&amp;source=placeapi]

    原创文章,转载请注明: 转载自http://www.qiyadeng.com/

    本文链接地址: 周边信息查询




  • 相关阅读:
    算法-第四版-练习1.3.2解答
    彻底理解线索二叉树(转载)
    C/C++——C++中new与malloc的10点区别(转载)
    C语言中的struct和typedef struct(转载)
    C语言实现贪吃蛇
    C语言实现2048小游戏
    案例开发准备
    WordCount单词计数
    MapReduce原理与实现
    HDFS简介
  • 原文地址:https://www.cnblogs.com/qiyadeng/p/2983620.html
Copyright © 2011-2022 走看看