Idea: The beginning is to get directly in the foreground, but cross-domain access is still a bit difficult, and the format must be JOSNP format, finally too troublesome, forced to give up.
I do the ASP. And this has its own parsing class, direct reference on the line
Get to Josn in the background first:
1 Private voidGetqzyzuobiaotomap (HttpContext context)2 {3 //determine if login is invalid4 if(Context. session["_user"] ==NULL)5 {6Writeresponse (Context,false,"you are not logged in or login is invalid! ");7 return;8 }9 //define a front-end pass-through string, get to the later can be directly into the Baidu API interface insideTen stringDialt = context. request["Dialt"]. Trim (); One //define a string to receive Baidu API interface sent back JOSN A stringstr =""; - //WebClient This method is the method that ASP. - using(WebClient client =NewWebClient ()) the { - //transcoding -Client. Encoding =System.Text.UTF8Encoding.UTF8; - //Dialt (String received by the foreground) +str = client. Downloadstring ("http://api.map.baidu.com/geocoder/v2/?address="+ Dialt +"&output=json&ak= here to write your Baidu AK"); - } + //return to this josn A context. Response.Write (str); at}
Then write an Ajax in the foreground JS to get this JSON:
//defines a string that can define a text box for user data, or a combo drop-down box //example 1:var Dialt = $.trim ($ ("#Dialt"). Val ()); //Example 2 var cityname = $ (' #cityName '). ComboBox (' GetText ') //var provisionname = $ (' #provisionName '). ComboBox (' GetText ') //var dialt = provisionname + cityname; //here is the Easyui drop-down box, if defined directly can also vardialt= "Ju Feng Township, Shiqian County, Tongren Prefecture, Guizhou province"//Longitude varLNG = ""; //Latitude varLat = ""; $.ajax ({URL:'/service/userserviceluo.ashx ', type:' Post ', data: {command:"3001032", //Pass a string pastDialt:dialt}, DataType:' JSON ', Async:false, Success:function(Result) {LNG= RESULT.RESULT.LOCATION.LNG;//Longitudelat = Result.result.location.lat;//Dimension of}, Error:function(x, MSG, E) {}}); varlongitude = LNG;//Longitude varLatitude = lat;//Latitude
Asp. NET get the JSON from the API interface provided by Baidu Map