使用您的公众账号登陆
;amp;output=html&source=placeapi
接下来,把百度地图反映出来的最近位置信息,以图文消息的格式展示给微信用户
public static String getWeChatReplyNewsMessageByBaiduPlace(ListplaceList, double lat, double lng,String userName, int size){ WeChatReplyNewsMessage newsMessage = new WeChatReplyNewsMessage(); List - items = new ArrayList
- (); StringBuffer strBuf = new StringBuffer(); logger.log(Level.INFO,"placeList count="+placeList.size()); newsMessage.setItems(items); if(placeList.size()>size){ newsMessage.setArticleCount(size); } else{ newsMessage.setArticleCount(placeList.size()); } logger.log(Level.INFO,"article count="+newsMessage.getArticleCount()); newsMessage.setCreateTime(new Date().getTime()+""); newsMessage.setMsgType("news"); newsMessage.setFuncFlag("0"); newsMessage.setToUserName(userName); newsMessage.setFromUserName(WeChatConstant.FROMUSERNAME); for(int i = 0;i
2.路名、标志性建筑或是商场名称
对路名、标志性建筑等信息,方法还是通过第三方地图信息,确定输入的位置信息的经度纬度。
本文使用百度地图API,确定所查找的位置的经度和纬度。
确定了经度和纬度,问题就变成和第1种消息类型一致了,根据经度纬度去做相应处理。
public String getGeoCode(String query) throws ClientProtocolException, IOException{ HttpClient httpClient = new DefaultHttpClient(); String url = geoCodeRequestUrl(query); logger.log(Level.INFO, url); HttpGet httpget = new HttpGet(url); ResponseHandlerresponseHandler = new BasicResponseHandler(); String responseBody = httpClient.execute(httpget, responseHandler); logger.log(Level.INFO,"baidu response:"+responseBody); return responseBody; } public String geoCodeRequestUrl(String query) throws UnsupportedEncodingException{ String url = WeChatConstant.BASEURL + "geocoder?address=" + URLEncoder.encode(query,"UTF-8") + "&key=" + WeChatConstant.MAPKEY + "&output=" + WeChatConstant.OUTPUTFORMAT; return url; }
更多微信公众平台开发系列 相关文章请关注PHP中文网!