bigtiger0905
Active Member
mình vừa tìm thấy code python xác định các giá trị lat & long dựa vào thông tin của trạm thu phát sóng và data của google.
google_location.py
nguồn: http://blog.jebu.net/2008/07/google-cell-tower-mapping-with-python-on-s60/
tuy nhiên mình chưa thể test được, mình xài pythonscriptshell 1.4.5 final và bộ powerpython4all.v.4.0.0.runall.pyapp
nhưng lại báo lỗi e:\private\2000b1a5\default.py line 81 , line 65.....
nhưng trong web nguồn có người đã báo:
Very nice work!
It actually works perfectly! Thank you very much
vậy nên ace nào test được code trên thì cho mình biết nên xài bộ python nào để test code đó, thanks all.
google_location.py
Mã:
from httplib import HTTP
import location
latitude = 0
longitude = 0
def doLookup(cellId, lac, host = "www.google.com", port = 80):
from string import replace
from struct import unpack
page = "/glm/mmap"
http = HTTP(host, port)
result = None
errorCode = 0
content_type, body = encode_request(cellId, lac)
http.putrequest('POST', page)
http.putheader('Content-Type', content_type)
http.putheader('Content-Length', str(len(body)))
http.endheaders()
http.send(body)
errcode, errmsg, headers = http.getreply()
result = http.file.read()
# could need some modification to get the answer: here I just need
# to get the 5 first characters
if (errcode == 200):
(a, b,errorCode, latitude, longitude, c, d, e) = unpack(">hBiiiiih",result)
latitude = latitude / 1000000.0
longitude = longitude / 1000000.0
return latitude, longitude
def encode_request(cellId, lac):
from struct import pack
content_type = 'application/binary'
body = pack('>hqh2sh13sh5sh3sBiiihiiiiii', 21, 0, 2, 'in', 13, "Nokia N95 8Gb", 5,"1.3.1", 3, "Web", 27, 0, 0, 3, 0, cellId, lac, 0, 0, 0, 0)
return content_type, body
(mcc, mnc, lac, cellId) = location.gsm_location()
(latitude, longitude) = doLookup(cellId, lac, "www.google.com", 80)
print latitude
print longitude
tuy nhiên mình chưa thể test được, mình xài pythonscriptshell 1.4.5 final và bộ powerpython4all.v.4.0.0.runall.pyapp
nhưng lại báo lỗi e:\private\2000b1a5\default.py line 81 , line 65.....
nhưng trong web nguồn có người đã báo:
Very nice work!
It actually works perfectly! Thank you very much
vậy nên ace nào test được code trên thì cho mình biết nên xài bộ python nào để test code đó, thanks all.