Use Baidu Map service to convert latitude and longitude to meters unit coordinates
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Net;usingSystem.IO;usingSystem.Diagnostics;namespaceconsoleapplication1{classProgram {Static voidMain (string[] args) { Double[,] Lonlat =New Double[2,2] { {114.21892734521,29.575429778924}, {114.21892734521,29.575429778924 } }; stringURL =string. Format ("Http://api.map.baidu.com/geoconv/v1/?coords={0},{1}; {2},{3}&from=1&to=6&ak= your key", lonlat[0,0], lonlat[0,1], lonlat[1,0], lonlat[1,1]); stringres =sendrequest (URL, Encoding.UTF8); Debug.WriteLine (RES); intx = Res. IndexOf ("\ "x\":"); inty = Res. IndexOf ("\ "y\":"); intEndy = Res. IndexOf ("}"); stringxx = Res. Substring (x+4, Y-x-5); stringyy = Res. Substring (y +4, endy-y-4); Console.Write (xx+"m"); Console.WriteLine (yy+"m"); X= Res. IndexOf ("\ "x\":", x+3); Y= Res. IndexOf ("\ "y\":", y+3); Endy= Res. IndexOf ("}", endy+3); XX= Res. Substring (x +4, Y-x-5); YY= Res. Substring (y +4, Endy-y-4); Console.Write (xx+"m"); Console.WriteLine (yy+"m"); } /// <summary> ///Get URL address output content/// </summary> /// <param name= "url" >URL</param> /// <param name= "encoding" >returns how content is encoded, for example: Encoding.UTF8</param> Public Staticstring sendrequest (string url, Encoding Encoding) {HttpWebRequest webRequest=(HttpWebRequest) webrequest.create (URL); Webrequest.method="GET"; HttpWebResponse WebResponse=(HttpWebResponse) webrequest.getresponse (); StreamReader SR=NewStreamReader (WebResponse.GetResponseStream (), encoding); returnSr. ReadToEnd (); } }}
Results:
Official Development Note: http://developer.baidu.com/map/changeposition.htm
Get key: Http://lbsyun.baidu.com/apiconsole/key
My own key: Http://lbsyun.baidu.com/apiconsole/key
Http://developer.baidu.com/map/jsdemo.htm#a1_2
The key also establishes a Web page showing the map
<!DOCTYPE HTML><HTML><Head> <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /> <Metaname= "Viewport"content= "initial-scale=1.0, User-scalable=no" /> <styletype= "Text/css">body, HTML, #allmap{width:100%;Height:100%;Overflow:Hidden;margin:0;font-family:"Microsoft Jas Black";} </style> <Scripttype= "Text/javascript"src= "http://api.map.baidu.com/api?v=2.0&ak= key"></Script> <title>Map Show</title></Head><Body> <DivID= "Allmap"></Div></Body></HTML><Scripttype= "Text/javascript"> //Baidu Map API features varMap= NewBmap.map ("Allmap"); //Create a Map instanceMap.centerandzoom (NewBmap.point (116.404, 39.915), One); //initialize map, set center point coordinates and map levelMap.addcontrol (NewBmap.maptypecontrol ()); //Add a Map type controlmap.setcurrentcity ("Beijing"); //set the city that the map displays this item is required to be setMap.enablescrollwheelzoom (true); //Turn on mouse wheel zoom</Script>
An open-source project about maps:
Http://greatmaps.codeplex.com/SourceControl/latest
Baidu Map coordinates conversion API and map API