日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
微信公眾平臺開發(fā)(三)位置信息的識別

位置識別這是實際應(yīng)用經(jīng)常應(yīng)用的消息,特別是很多商家,通過了解用戶位置,給用戶提供特別的產(chǎn)品或是商場的推薦。其中用戶可能發(fā)送兩種類型的消息:

創(chuàng)新互聯(lián)是一家專注于做網(wǎng)站、成都做網(wǎng)站與策劃設(shè)計,柞水網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設(shè)十余年,網(wǎng)設(shè)計領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:柞水等地區(qū)。柞水做網(wǎng)站價格咨詢:18980820575

1.微信地理位置信息

2.路名、標(biāo)志性建筑或是商場名稱

1.微信地理位置消息

認(rèn)識一下,微信地理位置消息,包含一些什么信息

  
 
 
 
  1.  
  2.  
  3.  
  4. 1351776360 
  5.  
  6. 23.134521 
  7. 113.358803 
  8. 20 
  9.  
  10. 1234567890123456 
  11.   

包含的主要信息有經(jīng)度緯度和Label的位置??梢愿鶕?jù)label中描述的位置信息,提供給用戶對應(yīng)的服務(wù)。也可根據(jù)用戶的經(jīng)度緯度信息,提供你最近的產(chǎn)品或是有地域性的產(chǎn)品。

首先根據(jù)微信的地理位置信息,定義WeChatLocationMessage類,并能把Xml轉(zhuǎn)換為WeChatLocationMessage對象

 
 
 
 
  1. public class WeChatLocationMessage { 
  2.     private String toUserName; 
  3.     private String fromUserName; 
  4.     private String createTime; 
  5.     private String msgType; 
  6.     private String locationx; 
  7.     private String localtiony; 
  8.     private String scale; 
  9.     private String label; 
  10.     private String msgId; 
  11.     public static WeChatLocationMessage getWeChatLocationMessage(String xml){ 
  12.         XStream xstream = new XStream(new DomDriver()); 
  13.         WeChatLocationMessage  message = null; 
  14.         xstream.alias("xml", WeChatLocationMessage.class); 
  15.         xstream.aliasField("ToUserName", WeChatLocationMessage.class, "toUserName"); 
  16.         xstream.aliasField("FromUserName", WeChatLocationMessage.class, "fromUserName"); 
  17.         xstream.aliasField("CreateTime", WeChatLocationMessage.class, "createTime"); 
  18.         xstream.aliasField("MsgType", WeChatLocationMessage.class, "msgType"); 
  19.         xstream.aliasField("Location_X", WeChatLocationMessage.class, "locationx"); 
  20.         xstream.aliasField("Location_Y", WeChatLocationMessage.class, "localtiony"); 
  21.         xstream.aliasField("Scale", WeChatLocationMessage.class, "scale"); 
  22.         xstream.aliasField("Label", WeChatLocationMessage.class, "label"); 
  23.         xstream.aliasField("MsgId", WeChatLocationMessage.class, "msgId"); 
  24.         message = (WeChatLocationMessage)xstream.fromXML(xml); 
  25.         return message; 
  26.     } 
  27. //getter and setter 

本文利用百度的地圖API,查找最近的銀行做為示例。

 
 
 
 
  1. public String getPalace(String query,String lat,String lng) throws ClientProtocolException, IOException{ 
  2.     HttpClient httpClient = new DefaultHttpClient(); 
  3.     String url = palceRequestUrl(query,lat,lng); 
  4.     logger.log(Level.INFO, url); 
  5.     HttpGet httpget = new HttpGet(url); 
  6.     ResponseHandler responseHandler = new BasicResponseHandler(); 
  7.     String responseBody = httpClient.execute(httpget, responseHandler); 
  8.     logger.log(Level.INFO,"baidu response:"+responseBody); 
  9.     return responseBody; 
  10.  
  11. public String palceRequestUrl(String query,String lat,String lng) throws UnsupportedEncodingException { 
  12.     String url = WeChatConstant.BASEURL + "place/search?query=" + URLEncoder.encode(query,"UTF-8") + "&key=" 
  13.             + WeChatConstant.MAPKEY +"&location="+lat+","+lng +"&radius=2000"+"&output=" + WeChatConstant.OUTPUTFORMAT; 
  14.     return url; 

輸出的結(jié)果

 
 
 
 
  1.  
  2.     OK 
  3.      
  4.          
  5.             中國工商銀行東長安街支行 
  6.              
  7.                 39.915891 
  8.                 116.41867 
  9.              
  10.             
    東城區(qū)東長安街1號東方廣場西三辦公樓1樓
     
  11.             a025683c73033c35a21de987 
  12.             http://api.map.baidu.com/place/detail?uid=a025683c73033c35a21de987&output=html&source=placeapi 
  13.              
  14.             銀行,王府井/東單 
  15.          
  16.        
  17.  

接下來,把百度地圖反映出來的最近位置信息,以圖文消息的格式展示給微信用戶

 
 
 
 
  1.     public static String getWeChatReplyNewsMessageByBaiduPlace(List placeList, double lat, double lng,String userName, int size){ 
  2.         WeChatReplyNewsMessage newsMessage = new WeChatReplyNewsMessage(); 
  3.         List items = new ArrayList(); 
  4.         StringBuffer strBuf = new StringBuffer(); 
  5.         logger.log(Level.INFO,"placeList count="+placeList.size()); 
  6.         newsMessage.setItems(items); 
  7.         if(placeList.size()>size){ 
  8.             newsMessage.setArticleCount(size); 
  9.         } 
  10.         else{ 
  11.             newsMessage.setArticleCount(placeList.size()); 
  12.         } 
  13.         logger.log(Level.INFO,"article count="+newsMessage.getArticleCount()); 
  14.         newsMessage.setCreateTime(new Date().getTime()+""); 
  15.         newsMessage.setMsgType("news"); 
  16.         newsMessage.setFuncFlag("0"); 
  17.         newsMessage.setToUserName(userName); 
  18.         newsMessage.setFromUserName(WeChatConstant.FROMUSERNAME); 
  19.         for(int i = 0;i 
  20.             BaiduPlaceResponse place = placeList.get(i); 
  21.             Double distance = GeoUtil.DistanceOfTwoPoints(Double.valueOf(place.getLng()), Double.valueOf(place.getLat()), lng, lat, GaussSphere.Beijing54); 
  22.             Item item = new Item(); 
  23.             item.setTitle(place.getName()+"["+distance+"米]"+"\n"+place.getAddress()+"\n"+place.getTelephone()); 
  24.             item.setPicUrl(""); 
  25.             item.setUrl(place.getDetailUrl()); 
  26.             item.setDescription(""); 
  27.             items.add(item); 
  28.         } 
  29. logger.log(Level.INFO,"newMessage="+newsMessage.toString()); 
  30.         strBuf = strBuf.append(getWeChatNewsMessage(newsMessage)); 
  31.         return strBuf.toString(); 
  32.     } 
  33.     public static String getWeChatNewsMessage(WeChatReplyNewsMessage newsMessage){ 
  34.         XStream xstream = new XStream(new DomDriver()); 
  35.         xstream.alias("xml", WeChatReplyNewsMessage.class); 
  36.         xstream.aliasField("ToUserName", WeChatReplyNewsMessage.class, "toUserName"); 
  37.         xstream.aliasField("FromUserName", WeChatReplyNewsMessage.class, "fromUserName"); 
  38.         xstream.aliasField("CreateTime", WeChatReplyNewsMessage.class, "createTime"); 
  39.         xstream.aliasField("MsgType", WeChatReplyNewsMessage.class, "msgType"); 
  40.         xstream.aliasField("ArticleCount", WeChatReplyNewsMessage.class, "articleCount"); 
  41.         xstream.aliasField("Content", WeChatReplyNewsMessage.class, "content"); 
  42.         xstream.aliasField("FuncFlag", WeChatReplyNewsMessage.class, "funcFlag"); 
  43.         xstream.aliasField("Articles", WeChatReplyNewsMessage.class, "items"); 
  44.         xstream.alias("item", Item.class); 
  45.         xstream.aliasField("Title", Item.class, "title"); 
  46.         xstream.aliasField("Description", Item.class, "description"); 
  47.         xstream.aliasField("PicUrl", Item.class, "picUrl"); 
  48.         xstream.aliasField("Url", Item.class, "url"); 
  49.         return xstream.toXML(newsMessage); 
  50.     } 

別走開,下頁更勁爆~

#p#

2.路名、標(biāo)志性建筑或是商場名稱

對路名、標(biāo)志性建筑等信息,方法還是通過第三方地圖信息,確定輸入的位置信息的經(jīng)度緯度。

本文使用百度地圖API,確定所查找的位置的經(jīng)度和緯度。

  
 
 
 
  1. public String getGeoCode(String query) throws ClientProtocolException, IOException{ 
  2.         HttpClient httpClient = new DefaultHttpClient(); 
  3.         String url = geoCodeRequestUrl(query); 
  4.         logger.log(Level.INFO, url); 
  5.         HttpGet httpget = new HttpGet(url); 
  6.         ResponseHandler responseHandler = new BasicResponseHandler(); 
  7.         String responseBody = httpClient.execute(httpget, responseHandler); 
  8.         logger.log(Level.INFO,"baidu response:"+responseBody); 
  9.         return responseBody; 
  10.     } 
  11.     public String geoCodeRequestUrl(String query) throws UnsupportedEncodingException{ 
  12.         String url = WeChatConstant.BASEURL + "geocoder?address=" + URLEncoder.encode(query,"UTF-8") + "&key=" 
  13.                 + WeChatConstant.MAPKEY + "&output=" + WeChatConstant.OUTPUTFORMAT; 
  14.         return url; 
  15.     } 

確定了經(jīng)度和緯度,問題就變成和第1種消息類型一致了,根據(jù)經(jīng)度緯度去做相應(yīng)處理。

3.源代碼

本文的代碼較長,提供源代碼下載

WeChatDemo下載

閱讀第一篇:微信公眾平臺開發(fā)(一)平臺綜述

閱讀第二篇:微信公眾平臺開發(fā)(二)簡單的聊天機器人

轉(zhuǎn)載自http://www.qiyadeng.com/

本文鏈接地址: 微信公眾平臺開發(fā)(三)–位置信息的識別


新聞名稱:微信公眾平臺開發(fā)(三)位置信息的識別
文章鏈接:http://www.dlmjj.cn/article/dpoogsg.html