This article details the geographical location of public platform development. net code, interested friends can refer to this article for details on the geographical location of public platform development. net code. if you are interested, refer
There are two geographical locations involved in the public platform:
First,I can send a custom location to automatically feedback the response information.
Second,Let's get the GPS location and feedback the response information.
First, let's look at the first one. in addition to sending texts, images, and audios, there is also a geographic location. according to XML information that accepts geographic information, we need to modify the previous wxmessage class with several attributes:
Class wxmessage {public string FromUserName {get; set;} public string ToUserName {get; set;} public string MsgType {get; set;} public string EventName {get; set ;} public string Content {get; set;} public string Recognition {get; set;} public string MediaId {get; set;} public string EventKey {get; set ;} public string Location_X {get; set;} public string Location_Y {get; set;} pu Blic string Scale {get; set;} public string Label {get; set ;}where Location_X represents the latitude, Location_Y represents the longitude, and Scale represents the scaling ratio, label indicates the location description and accepted text. for a voice message, the MsgType of the geographic information is "location". modify the previous GetWxMessage () function and the message processing in OnLoad: private wxmessage GetWxMessage () {wxmessage wx = new wxmessage (); StreamReader str = new StreamReader (Request. inputStream, System. text. encoding. UTF8); XmlDocument xml = new XmlDocument (); xml. load (Str); wx. toUserName = xml. selectSingleNode ("xml "). selectSingleNode ("ToUserName "). innerText; wx. fromUserName = xml. selectSingleNode ("xml "). selectSingleNode ("FromUserName "). innerText; wx. msgType = xml. selectSingleNode ("xml "). selectSingleNode ("MsgType "). innerText; if (wx. msgType. trim () = "text") {wx. content = xml. selectSingleNode ("xml "). selectSingleNode ("Content "). innerText;} if (wx. msgType. trim () = "Location") {wx. location_X = xml. selectSingleNode ("xml "). selectSingleNode ("Location_X "). innerText; wx. location_Y = xml. selectSingleNode ("xml "). selectSingleNode ("Location_Y "). innerText; wx. scale = xml. selectSingleNode ("xml "). selectSingleNode ("Scale "). innerText; wx. label = xml. selectSingleNode ("xml "). selectSingleNode ("Label "). innerText;} if (wx. msgType. trim () = "event") {wx. eventName = xml. S ElectSingleNode ("xml "). selectSingleNode ("Event "). innerText; wx. eventKey = xml. selectSingleNode ("xml "). selectSingleNode ("EventKey "). innerText;} if (wx. msgType. trim () = "voice") {wx. recognition = xml. selectSingleNode ("xml "). selectSingleNode ("Recognition "). innerText;} return wx;} protected void Page_Load (object sender, EventArgs e) {wxmessage wx = GetWxMessage (); string res = ""; if (! String. IsNullOrEmpty (wx. EventName) & wx. EventName. Trim () = "subscribe") {string content = ""; if (! Wx. eventKey. contains ("qrscene _") {content = "/: rose welcome Beijing Yongjie Youxin Technology Co., Ltd./: rose \ n directly reply" Hello ""; res = sendTextMessage (wx, content);} else {content = "QR Code parameter: \ n" + wx. eventKey. replace ("qrscene _", ""); res = sendTextMessage (wx, content) ;}} else if (! String. isNullOrEmpty (wx. eventName) & wx. eventName. toLower () = "scan") {string str = "QR Code parameter: \ n" + wx. eventKey; res = sendTextMessage (wx, str);} else if (! String. isNullOrEmpty (wx. eventName) & wx. eventName. trim () = "CLICK") {if (wx. eventKey = "HELLO") res = sendTextMessage (wx, "HELLO, welcome to Beijing Yongjie Youxin Technology Co., Ltd. public platform! ");} Else {WriteLog (wx. msgType); if (wx. msgType = "text" & wx. content = "Hello") {res = sendTextMessage (wx, "Hello, welcome to Beijing Yongjie Youxin Technology Co., Ltd. public platform! ");} Else if (wx. msgType = "voice") {res = sendTextMessage (wx, wx. recognition);} else if (wx. msgType = "location") {res = sendTextMessage (wx, "your sending location is:" + wx. label + "; Latitude:" + wx. location_X + "; Longitude:" + wx. location_Y + "; scaling ratio:" + wx. scale);} else {res = sendTextMessage (wx, "Hello, failed to recognize the message! ") ;}} Response. Write (res );}
In this way, when we send a geographic location information, we can feed back the response information. It is worth mentioning that no authorization is required for the location of the geographical information here, because the location of the geographical information sent by yourself is not necessarily your actual location. we can choose any location on the input interface, privacy is not involved.
Of course, if we create a feature similar to "near me", we must have two conditions to enable the feature of obtaining user geographic information in the public number. Second, the user can allow the public number to retrieve my location when paying attention to it. This requires the second situation we introduced at the beginning of the article. According to the explanation, when a session starts (that is, when the dialog page is displayed), it is obtained first and then automatically obtained every five seconds. That is to say, when obtaining user location information, the trigger is not a "one-word conversation", but a special event that starts every five seconds. This is defined as MsgType as "event". to distinguish it from other "events", its EventName (officially called event) is "LOCATION" (in upper case ).
Below I still need to modify our wxmessage class according to the format:
Class wxmessage {public string FromUserName {get; set;} public string ToUserName {get; set;} public string MsgType {get; set;} public string EventName {get; set ;} public string Content {get; set;} public string Recognition {get; set;} public string MediaId {get; set;} public string EventKey {get; set ;} public string Location_X {get; set;} public string Location_Y {get; set;} public string Scale {get; set;} public string Label {get; set ;} public string Latitude {get; set;} public string longpolling {get; set;} public string Precision {get; set ;}transform the GetWxMessage () and OnLoad functions: private wxmessage GetWxMessage () {wxmessage wx = new wxmessage (); StreamReader str = new StreamReader (Request. inputStream, System. text. encoding. UTF8); XmlDocument xml = new XmlDocument (); xml. load (str); wx. toUserName = xml. selectSingleNode ("xml "). selectSingleNode ("ToUserName "). innerText; wx. fromUserName = xml. selectSingleNode ("xml "). selectSingleNode ("FromUserName "). innerText; wx. msgType = xml. selectSingleNode ("xml "). selectSingleNode ("MsgType "). innerText; WriteLog ("MsgType:" + wx. msgType); if (wx. msgType. trim () = "event") {wx. eventName = xml. selectSingleNode ("xml "). selectSingleNode ("Event "). innerText; WriteLog (wx. eventName); if (wx. eventName. toUpper () = "LOCATION") {wx. latitude = xml. selectSingleNode ("xml "). selectSingleNode ("Latitude "). innerText; wx. longpolling = xml. selectSingleNode ("xml "). selectSingleNode ("longpolling "). innerText; wx. precision = xml. selectSingleNode ("xml "). selectSingleNode ("Precision "). innerText;} else {wx. eventKey = xml. selectSingleNode ("xml "). selectSingleNode ("EventKey "). innerText ;}} if (wx. msgType. trim () = "text") {wx. content = xml. selectSingleNode ("xml "). selectSingleNode ("Content "). innerText;} if (wx. msgType. trim () = "location") {wx. location_X = xml. selectSingleNode ("xml "). selectSingleNode ("Location_X "). innerText; wx. location_Y = xml. selectSingleNode ("xml "). selectSingleNode ("Location_Y "). innerText; wx. scale = xml. selectSingleNode ("xml "). selectSingleNode ("Scale "). innerText; wx. label = xml. selectSingleNode ("xml "). selectSingleNode ("Label "). innerText;} if (wx. msgType. trim () = "voice") {wx. recognition = xml. selectSingleNode ("xml "). selectSingleNode ("Recognition "). innerText;} return wx ;}
When MsgType is event, we used a menu event. now we need to add a code segment whose EventName is "LOCATION, because there are no other events involved, I will use else later, and I will standardize the code later. Assign values to the three new attributes here, and then modify the Onload function.
Protected void Page_Load (object sender, EventArgs e) {wxmessage wx = GetWxMessage (); string res = ""; if (! String. IsNullOrEmpty (wx. EventName) & wx. EventName. Trim () = "subscribe") {string content = ""; if (! Wx. eventKey. contains ("qrscene _") {content = "/: rose welcome Beijing Yongjie Youxin Technology Co., Ltd./: rose \ n directly reply" Hello ""; res = sendTextMessage (wx, content);} else {content = "QR Code parameter: \ n" + wx. eventKey. replace ("qrscene _", ""); res = sendTextMessage (wx, content) ;}} else if (! String. isNullOrEmpty (wx. eventName) & wx. eventName. toLower () = "scan") {string str = "QR Code parameter: \ n" + wx. eventKey; res = sendTextMessage (wx, str);} else if (! String. isNullOrEmpty (wx. eventName) & wx. eventName. trim () = "CLICK") {if (wx. eventKey = "HELLO") res = sendTextMessage (wx, "HELLO, welcome to Beijing Yongjie Youxin Technology Co., Ltd. public platform! ");} Else if (! String. isNullOrEmpty (wx. eventName) & wx. eventName. trim () = "LOCATION") {res = sendTextMessage (wx, "your LOCATION is Longitude:" + wx. latitude + ", dimension:" + wx. longpolling + ", geographic Longitude:" + wx. precision);} else {if (wx. msgType = "text" & wx. content = "Hello") {res = sendTextMessage (wx, "Hello, welcome to Beijing Yongjie Youxin Technology Co., Ltd. public platform! ");} Else if (wx. msgType = "voice") {res = sendTextMessage (wx, wx. recognition);} else if (wx. msgType = "location") {res = sendTextMessage (wx, "your sending location is:" + wx. label + "; Latitude:" + wx. location_X + "; Longitude:" + wx. location_Y + "; scaling ratio:" + wx. scale);} else {res = sendTextMessage (wx, "Hello, failed to recognize the message! ") ;}} Response. Write (res );}
Now, when you enable "get user location information", the platform will remind you whether to access the session for the first time or every 5 seconds, if you select the latter, you will see that every 5 seconds, you will be given a geographical location information.
It should be noted that I think it is okay, but I cannot get the information because when I enter the session, you will see that your mobile phone GPS is searching. before GPS positioning, you will not see the content. It can be understood in this way that only when you search for a location by GPS will an event be triggered to obtain the user's location information. this is not what I think the base station positioning can also obtain the approximate location, this requires developers to note that I just spent a long time waiting for me to go out and locate the phone and accidentally see the response.
Speaking of this, you may ask only what is the use of latitude and longitude coordinates? It is not a specific location. Otherwise, we can use multiple methods to know detailed location information. for example, we can use the address reverse resolution of the BaiduMap API to guide the coordinates in that city, that street, and so on, I can even know the situation nearby, so I will not talk about it here. I will have a chance to talk with you about BaiduMap in the future.
The above is a detailed description of the geographic location instance of the. NET development public platform. For more information, see other related articles on the php Chinese network!