您的位置:首页 > 编程语言 > Python开发

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

2010-09-21 15:09 183 查看
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()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: