Asp. NET get the JSON from the API interface provided by Baidu Map

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.