谷歌地图,细胞到位置 [英] google maps, cellid to location

查看:192
本文介绍了谷歌地图,细胞到位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据这个例子:

http://www.codeproject.com/KB/mobile/DeepCast.aspx



有可能要求GPS坐标(经度和纬度)包括发送cellid信息时的范围(MCC,MNC,towerid等)

有人可以告诉我请求/张贴到这个地址的实际参数吗?



http://www.google.com/glm/mmap

可能是这样的

  http: //www.google.com/glm/mmap?mcc=xxx&mnc=xxx&towerid=xxx 

我想知道我们会得到什么回应。



我观察过OpenCellid网站,他们提供了一些很好的API,但我想知道在谷歌地图也(因为他们有更完整的数据库)。



OpenCellID API

解决方案



 #!/ usr / bin / python 

country ='fr'
#device ='Sony_Ericsson-K750'
device =Nokia N95 8Gb
user_agent ='Mozilla / 4.0(compatible; MSIE 5.5; Windows NT)'
mmap_url ='http://www.google.com/glm/mmap'
geo_url ='http://maps.google.com/maps/geo'

from struct import pack,解开httplib中的
import HTTP
import urllib2
$ b def fetch_latlong_http(query):
http = HTTP('www.google .com',80)
http.putrequest('POST','/ glm / mmap')
http.putheader('Content-Type','application / binary')
http .putheader('Content-Length',str(len(query)))
http.endheaders()
http.send(query)
code,msg,headers = http.getreply )
结果= http.file.read()
返回结果

def fetch_latlong_urllib(query):
headers = {'User-Agent':user_agent}
req = urllib2.Request(mmap_url,query,headers)
resp = urllib2.urlopen(req)
response = resp.read()
返回响应

fetch_latlong = fetch_latlong_http

def get_location_by_cell(cid,lac,mnc = 0,mcc = 0, country ='fr'):
b_string = pack('> hqh2sh13sh5sh3sBiiihiiiiii',
21,0,
len(country),country,
len(device),device ,
len('1.3.1'),1.3.1,
len('Web'),Web,
27,0,0,
3 ,0,cid,lac,
0,0,0,0)

字节= fetch_latlong(b_string)
(a,b,errorCode,纬度,经度,c, d,e)=解包(> hBiiiiih,字节)
纬度=纬度/ 1000000.0
经度=经度/ 1000000.0

返回纬度,经度

def get_location_by_geo(纬度,经度):
url ='%s?q =%s,%s& output = json& oe = utf8'(geo_url,str(latitude),str(longitude) )
返回urllib2.urlopen(url).read()
$ b $如果__name__ =='__main__':
print get_location_by_cell(20465,495,3,262)
打印g et_location_by_cell(20442,6015)
print get_location_by_cell(1085,24040)
print get_location_by_geo(40.714224,-73.961452)
print get_location_by_geo(13.749113,100.565327)


According to this sample:

http://www.codeproject.com/KB/mobile/DeepCast.aspx

It's possible to request a gps coordinate (longitude & latitude) including range when sending cellid information (MCC, MNC, towerid, etc)

Can someone tell me the actual parameter to request/post to this address?

http://www.google.com/glm/mmap

It could be something like this

http://www.google.com/glm/mmap?mcc=xxx&mnc=xxx&towerid=xxx

And i would like to know what response we would get.

I have observe OpenCellid website and they provide some nice API to begin with, but i want to know about that in google map too (since they have more completed database).

OpenCellID API

解决方案

Here is example for work with

#!/usr/bin/python

country = 'fr'
#device = 'Sony_Ericsson-K750'
device = "Nokia N95 8Gb"
user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
mmap_url = 'http://www.google.com/glm/mmap'
geo_url = 'http://maps.google.com/maps/geo'

from struct import pack, unpack
from httplib import HTTP
import urllib2

def fetch_latlong_http(query):
    http = HTTP('www.google.com', 80)
    http.putrequest('POST', '/glm/mmap')
    http.putheader('Content-Type', 'application/binary')
    http.putheader('Content-Length', str(len(query)))
    http.endheaders()
    http.send(query)
    code, msg, headers = http.getreply()
    result = http.file.read()
    return result

def fetch_latlong_urllib(query):
    headers = { 'User-Agent' : user_agent }
    req = urllib2.Request(mmap_url, query, headers)
    resp = urllib2.urlopen(req)
    response = resp.read()
    return response

fetch_latlong = fetch_latlong_http

def get_location_by_cell(cid, lac, mnc=0, mcc=0, country='fr'):
    b_string = pack('>hqh2sh13sh5sh3sBiiihiiiiii',
                    21, 0,
                    len(country), country,
                    len(device), device,
                    len('1.3.1'), "1.3.1",
                    len('Web'), "Web",
                    27, 0, 0,
                    3, 0, cid, lac,
                    0, 0, 0, 0)

    bytes = fetch_latlong(b_string)
    (a, b,errorCode, latitude, longitude, c, d, e) = unpack(">hBiiiiih",bytes)
    latitude = latitude / 1000000.0
    longitude = longitude / 1000000.0

    return latitude, longitude

def get_location_by_geo(latitude, longitude):
    url = '%s?q=%s,%s&output=json&oe=utf8' % (geo_url, str(latitude), str(longitude))
    return urllib2.urlopen(url).read()

if __name__ == '__main__':
    print get_location_by_cell(20465, 495, 3, 262)
    print get_location_by_cell(20442, 6015)
    print get_location_by_cell(1085, 24040)
    print get_location_by_geo(40.714224, -73.961452)
    print get_location_by_geo(13.749113, 100.565327)

这篇关于谷歌地图,细胞到位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆