用Python通过CellID从Google得到经纬度

1. 应用Geolocation API Network Protocol接口

http://code.google.com/intl/zh-CN/apis/gears/geolocation_network_protocol.html#example

 

2. Python+JSON

 

3. 说明:

 

访问的URL:http://www.google.com/loc/json

 

JSON数据的格式请参考GoogleAPI文档

 

 

代码:

 

# -*- coding: utf-8 -*- # # Author: Jack Ding # # 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": 11308,/ "location_area_code": 4269,/ "mobile_country_code": 460,/ "mobile_network_code": 0/ }/ ]/ }' 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()

你可能感兴趣的:(python,Google,url,mobile,Access,NetWork)