protected void Page_Load (object sender, EventArgs e)
{
//get current Latitude stringLatitude ="117.707677"; //Get current longitude stringLongitude ="39.084097"; //Baidu coordinate conversion API stringPath ="http://api.map.baidu.com/ag/coord/convert?from=0&to=4&x="+ Latitude +"&y="+ Longitude +""; HttpWebRequest WebRequest=(HttpWebRequest) webrequest.create (path); Webrequest.method="GET"; HttpWebResponse WebResponse=(HttpWebResponse) webrequest.getresponse (); StreamReader SR=NewStreamReader (WebResponse.GetResponseStream (), Encoding.UTF8); stringStrjson =Sr. ReadToEnd (); JavaScriptSerializer JS=NewJavaScriptSerializer (); Mapconvert MC= js. Deserialize<mapconvert>(Strjson); if(Mc.error = ="0") { stringLon =mc.x; stringLat =mc.y; //perform Base64 decoding byte[] Xbuffer =convert.frombase64string (LON); stringStrx = Encoding.UTF8.GetString (Xbuffer,0, xbuffer.length); byte[] Ybuffer =convert.frombase64string (LAT); stringStry = Encoding.UTF8.GetString (Ybuffer,0, xbuffer.length); stringStrB = Strx +","+Stry; } Else { stringStrB ="Get failed"; } } } Public classMapconvert { Public stringError {Get;Set; } Public stringx {Get;Set; } Public stringY {Get;Set; } }
C # background GPS coordinates converted into Baidu coordinates