C # call Baidu Map Web Services API-----This method can be used on JS Cross-domain request

Source: Internet
Author: User


The Baidu Map Web Services API provides developers with an HTTP interface, in which the developer initiates a retrieval request via HTTP, retrieving the retrieved data in JSON or XML format. Based on this, users can develop the map application of JavaScript, C #, C + +, Java and so on.


API website Description Link:

Http://developer.baidu.com/map/webservice.htm



Available Interface enumeration:

Get related address hint place suggestion
http://api.map.baidu.com/place/v2/suggestion?query= Metasequoia &region= Chengdu &output=json&ak= 42b8ececa9cd6fe72ae4cddd77c0da5d



Get coordinates geocoding

http://api.map.baidu.com/geocoder?address= Jinjiang District No. 299 Ling ' an road, &output=json&key=42b8ececa9cd6fe72ae4cddd77c0da5d



http://api.map.baidu.com/place/v2/search?ak=42b8ececa9cd6fe72ae4cddd77c0da5d&output=json&query= Blu-ray Coco Sands &page_size=10&page_num=0&scope=1&region= Chengdu


{
"Status": 0,
"Message": "OK",
"Total": 2,
"Results": [
{
"Name": "Blu-ray Coco Sands",
"Location": {
"Lat": 30.687544,
"LNG": 103.996691
},
"Address": "West three ring outside the Jinsha West Source Avenue (It Avenue)",
"UID": "223992992C5EE7E0841541DF"
},
{
"Name": "Blu-ray Coco Sands Phase 2",
"Location": {
"Lat": 30.681123,
"LNG": 103.991123
},
"Address": "Qingyang District Sands it Boulevard",
"UID": "b7bb5abb1cd4982213293580"
}
]
}


Facilities navigation
http://api.map.baidu.com/place/v2/search?ak=42b8ececa9cd6fe72ae4cddd77c0da5d&output=json&query= Library &page_size=20&page_num=0&scope=2&region= Chengdu




The results of obtaining the coordinate interface directly in the browser request are as follows:





The C # call gets the coordinate interface code as follows:


Create a new console program



Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Net;

Namespace Test
{
    class program
    {
        Private const String Baidu_app_key = " 42B8ECECA9CD6FE72AE4CDDD77C0DA5D ";
        Private Const String A = "188th Metasequoia Street";
      
     
        static void Main (string[] args)
        {
            WebClient client = new WebClient ();
          String json = client. Downloadstring ("http://api.map.baidu.com/geocoder?address=" + A + "&output=json&key=" + baidu_app_key);
            Client. Encoding = Utf8encoding.utf8;
            Console.WriteLine (JSON);
            Console.readkey ();}}

Run Result:


Related Article

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.