【问题标题】:google maps, cellid to location谷歌地图,cellid到位置
【发布时间】:2010-12-08 14:15:57
【问题描述】:

根据此示例:

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

在发送 cellid 信息(MCC、MNC、towerid 等)时,可以请求 GPS 坐标(经度和纬度),包括范围

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

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

可能是这样的

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

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

我观察了 OpenCellid 网站,他们提供了一些不错的 API,但我也想在谷歌地图中了解这一点(因为他们有更多完整的数据库)。

OpenCellID API

【问题讨论】:

  • 我不确定。但是使用 Google 地图,似乎只要我的地方有新的 Cell ID,几周或一个月后,Google 地图就会更新该 Cell ID。
  • 这个 API 是否可以反过来使用,我们有 lat/long 并希望在响应中列出最近的可用单元格标识符?

标签: coordinates google-maps mashup cellid


【解决方案1】:

这是使用的示例

#!/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)

【讨论】:

  • 但是设备参数需要什么?在网站中它不是必需的。谢谢
  • 我正在尝试打包函数,它给了我数据错误 (745522,22,874,405) 并且错误是 struct.error: 's' 的参数必须是字节对象。看看你能不能解释一下谷歌 mmap 的包装规范到底是什么。
【解决方案2】:

您可以使用 Firefox 使用的 Google Location API(示例参见 http://www.mozilla.com/en-US/firefox/geolocation/),其 URL 为 www.google.com/loc/json/。实际上这是基于 JSON 的 web 服务和一个最小的 Perl 示例看起来像这样:

use LWP;

my $ua = LWP::UserAgent->new;
$ua->agent("TestApp/0.1 ");
$ua->env_proxy();

my $req = HTTP::Request->new(POST => 'https://www.google.com/loc/json');

$req->content_type('application/jsonrequest');
$req->content('{"cell_towers": [{"location_area_code": "8721", "mobile_network_code": "01", "cell_id": "7703", "mobile_country_code": "262"}], "version": "1.1.0", "request_address": "true"}');

# Pass request to the user agent and get a response back
my $res = $ua->request($req);

# Check the outcome of the response
if ($res->is_success) {
    print $res->content;
} else {
    print $res->status_line, "\n";
    return undef;
}

请注意,Google 尚未正式开放此 API 用于其他用途...

【讨论】:

【解决方案3】:

Google 位置 API 的新位置如下: https://developers.google.com/maps/documentation/geolocation/intro

使用此 API,您可以从 Cell 信息(cellid、mcc、mnc 和 lac)中检索位置

【讨论】:

  • 这家伙!希望我能投票一百次。发现。简单得多且文档齐全的界面!
【解决方案4】:

基于GeolocationAPI,以下是我的部分代码:

import java.io.IOException;
import java.io.StringWriter;
import java.net.HttpURLConnection;
import java.net.URL;

//http://code.google.com/p/google-gson/
import com.google.gson.stream.JsonWriter;

...

/**
 * Requests latitude and longitude from Google.
 * 
 * @param gsmParams
 *            {@link GsmParams}
 * @return an {@link HttpURLConnection} containing connection to Google
 *         lat-long data.
 * @throws IOException
 */
public HttpURLConnection requestLatlongFromGoogle(GsmParams gsmParams)
        throws IOException {
    // prepare parameters for POST method
    StringWriter sw = new StringWriter();
    JsonWriter jw = new JsonWriter(sw);
    try {
        jw.beginObject();

        jw.name("host").value("localhost");
        jw.name("version").value("1.1.0");
        jw.name("request_address").value(true);

        jw.name("cell_towers");

        jw.beginArray().beginObject();

        jw.name("cell_id").value(gsmParams.getCid());
        jw.name("location_area_code").value(gsmParams.getLac());
        jw.name("mobile_network_code").value(gsmParams.getMnc());
        jw.name("mobile_country_code").value(gsmParams.getMcc());

        jw.endObject().endArray().endObject();
    } finally {
        try {
            jw.close();
        } catch (IOException ioe) {
        }
        try {
            sw.close();
        } catch (IOException ioe) {
        }
    }
    final String JsonParams = sw.toString();
    final String GoogleLocJsonUrl = "http://www.google.com/loc/json";

    // post request
    URL url = null;
    HttpURLConnection conn = null;
    url = new URL(GoogleLocJsonUrl);
    conn = (HttpURLConnection) url.openConnection();
    conn.setConnectTimeout((int) 30e3);
    conn.setReadTimeout((int) 30e3);

    conn.setDoOutput(true);
    conn.setRequestMethod("POST");
    conn.getOutputStream().write(JsonParams.getBytes());
    conn.getOutputStream().flush();
    conn.getOutputStream().close();
    int resCode = conn.getResponseCode();
    if (resCode == Http_BadRequest || resCode != Http_Ok) {
        throw new IOException(String.format(
                "Response code from Google: %,d", resCode));
    }
    return conn;
}

对象GsmParams 只是一个Java bean,包含GSM 参数MCC、MNC、LAC、CID。我认为您可以轻松创建相同的类。

获得连接后,您可以拨打conn.getInputStream() 并从谷歌地图获取结果。然后使用JsonReader解析数据...

【讨论】:

  • 自 2011 年 3 月以来 Google Gears 已关闭,是时候告别为 Google Gears 提供支持的 Geolocation API。 Google Gears Geolocation API 将于 2012 年 11 月 17 日停止响应请求。
【解决方案5】:

正如其他线程中所述,还可以查看 https://labs.ericsson.com/apis/mobile-location/documentation/cell-id-look-up-api 以获取免费的 cell-ID 数据库,以获取来自 cellid、mcc、mnc 和 lac 的坐标。

【讨论】:

  • 我需要确切了解的是关于 google 服务 (api),但感谢您的建议,哦,是的,我已将 OpenCellID 视为替代服务
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-01-03
  • 1970-01-01
  • 1970-01-01
  • 2013-08-27
  • 2014-08-07
  • 2015-04-07
  • 1970-01-01
相关资源
最近更新 更多