最近,要做个关于地图的东西。简单的看了几个地图,发现百度地图还是不错的,谷歌地图收费的就不考虑了,MapABC和mapbar只提供客户端接口,什么falsh了啊,javascript了,好像只有百度地图有服务器端的接口。
贴一下python写的小demo:(
# coding=utf-8 import urllib import urllib2 map_api_url = 'http://api.map.baidu.com/geocoder/v2/?' ak = '38dbc1cdbb8170d3f08a4db190de55d2' # 地址解析 def geocoder(address, city='北京市'): query_args = { 'address':address, 'city':city, 'output':'xml', 'ak':ak} encoded_args = urllib.urlencode(query_args) render_url(map_api_url + encoded_args) # 逆地址解析 def geodecoder(lat, lng, pois=0): location = "%f,%f" % (lat, lng) output = 'xml' query_args = 'location=%s&ak=%s&output=%s&pois=%d' % \ (location, ak, output, pois) render_url(map_api_url + query_args) def render_url(url): response = urllib2.urlopen(url) headers = response.info() data = response.read() response.close() show_response(headers, data) return data def show_response(headers, data): print 'Headers :' print '----------' print headers print 'Data :' print '----------' print data.decode('utf-8') if __name__ == '__main__': geocoder('橘子洲', '长沙市') lat = 28.175617295411 lng = 112.96695042246 geodecoder(lat, lng, 1)