百度地图Web服务API为开发者提供http接口,即开发者通过http形式发起检索请求,获取返回json或xml格式的检索数据。用户可以基于此开发JavaScript、C#、C++、Java等语言的地图应用。
api官网说明链接:
http://developer.baidu.com/map/webservice.htm
可用接口列举:
获取相关地址提示 place suggestion
http://api.map.baidu.com/place/v2/suggestion?query=水杉®ion=成都&output=json&ak=42b8ececa9cd6fe72ae4cddd77c0da5d
获取坐标 geocoding
http://api.map.baidu.com/geocoder?address=锦江区菱安路299号&output=json&key=42b8ececa9cd6fe72ae4cddd77c0da5d
http://api.map.baidu.com/place/v2/search?ak=42b8ececa9cd6fe72ae4cddd77c0da5d&output=json&query=蓝光coco金沙&page_size=10&page_num=0&scope=1®ion=成都
{
"status":0,
"message":"ok",
"total":2,
"results":[
{
"name":"蓝光COCO金沙",
"location":{
"lat":30.687544,
"lng":103.996691
},
"address":"西三环外金沙西源大道(IT大道旁)",
"uid":"223992992c5ee7e0841541df"
},
{
"name":"蓝光COCO金沙2期",
"location":{
"lat":30.681123,
"lng":103.991123
},
"address":"青羊区金沙IT大道旁",
"uid":"b7bb5abb1cd4982213293580"
}
]
}
设施导航
http://api.map.baidu.com/place/v2/search?ak=42b8ececa9cd6fe72ae4cddd77c0da5d&output=json&query=图书馆&page_size=20&page_num=0&scope=2®ion=成都
获取坐标接口直接在浏览器请求的结果如下:
c#调用 获取坐标接口 代码 如下:
新建一个控制台程序
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 = "水杉街188号";
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();
}
}
}
运行结果: