2012年5月30日星期三
JSON方式Google API基站
# -*- coding: utf-8 -*-
import os
import sys
import json
import httplib
s1='{\
"version": "1.1.0",\
"host": "maps.google.com",\
"access_token": "2:k7j3G6LaL6u_lafw:4iXOeOpTh1glSXe",\
"request_address": true,\
"address_language": "zh_CN",\
"cell_towers": [\
{\
"cell_id": 21320851,\
"location_area_code": 42245,\
"mobile_country_code": 460,\
"mobile_network_code": 1\
}\
]\
}'
print s1
class TestJSON():
server_url = "www.google.com"
def __init__(self):
print u"start"
def run(self):
global s1
#socket.setdefaulttimeout(10)
print u"Start connection"
self.conn = httplib.HTTPConnection(self.server_url)
#self.conn.set_debuglevel(5)
request_url = "/loc/json"
req_headers = { "Content-Type" : "application/json" }
req_body = s1
self.conn.request("POST", request_url, body = req_body, headers = req_headers )
res = self.conn.getresponse()
http_status = res.status
http_reason = res.reason
print res
msg = res.read()
print u"msg=", msg
if __name__ == "__main__":
app = TestJSON()
app.run()
代码执行结果:
start
Start connection
据说,Google对基站位置的查询结果比运营商自己的数据还准确。
订阅 博文 [Atom]