google maps, cellid to location
Asked Answered
I

5

15

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

Ial answered 21/10, 2009 at 4:18 Comment(2)
I'm not sure. But with Google Maps, it seems whenever my place has new Cell ID, after some weeks or a month, Google Maps updates that Cell ID.Tedi
Is this API available the other way round, where we have lat/long and want the nearest available cell identifiers list in the response?Marikomaril
P
8

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)
Proconsulate answered 28/7, 2010 at 20:0 Comment(3)
But what the need of device parameter ? in the web sites it is not required. ThanksSpray
I was trying pack function and it gives me error for data (745522,22,874,405) and error is struct.error: argument for 's' must be a bytes object. see if you can explain what exactly is packing spec from google mmap.Rabi
@Rabi Take a look here developers.google.com/maps/documentation/geolocation/intro Script above 7 years oldProconsulate
M
8

You could use the Google Location API which is used by Firefox (Example see at http://www.mozilla.com/en-US/firefox/geolocation/ ) which has the url www.google.com/loc/json/. In fact this is JSON based webservice and a minimal Perl Example Look like this:

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;
}

Please keep in mind that Google has not officially opened this API for other uses...

Madoc answered 20/3, 2010 at 15:57 Comment(2)
thank you Lairs dragon, i've write Ruby version here bintangjatuh.com/2011/01/27/ruby-cellid-to-location.htmlAfrit
Since a few month now this does not longer work. Its not clear for me if you now have to use an API Key in the request or if the functionality has removed from the API.Madoc
P
8

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)
Proconsulate answered 28/7, 2010 at 20:0 Comment(3)
But what the need of device parameter ? in the web sites it is not required. ThanksSpray
I was trying pack function and it gives me error for data (745522,22,874,405) and error is struct.error: argument for 's' must be a bytes object. see if you can explain what exactly is packing spec from google mmap.Rabi
@Rabi Take a look here developers.google.com/maps/documentation/geolocation/intro Script above 7 years oldProconsulate
W
7

The new place for the Google location API is the following : https://developers.google.com/maps/documentation/geolocation/intro

With this API, you can retrieve a location from Cell information (cellid, mcc, mnc, and lac)

Welt answered 30/9, 2015 at 14:9 Comment(1)
This guy! Wish I could vote a hundred times. Spot on. Much much simpler and well documented interface!Unearthly
T
4

Base on GeolocationAPI, here are some parts of my code:

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;
}

The object GsmParams is just a Java bean containing GSM parameters MCC, MNC, LAC, CID. I think you can create a same class easily.

After getting connection, you can call conn.getInputStream() and get results from Google Maps. Then use JsonReader to parse data...

Tedi answered 20/2, 2012 at 16:10 Comment(1)
Since Google Gears has been shut down since March 2011, the time has come to also say goodbye to the Geolocation API that powered Google Gears. The Google Gears Geolocation API will stop responding to requests on November 17, 2012.Eldoneldora
T
1

As noted in other threads also check out https://labs.ericsson.com/apis/mobile-location/documentation/cell-id-look-up-api for a free cell-ID database to get coordinates from cellid, mcc, mnc, and lac .

Tonietonight answered 21/10, 2009 at 17:11 Comment(1)
what i need to know exactly is about google services (api), but thanks for suggestion, oh yeah i have look OpenCellID as alternate serviceIal

© 2022 - 2024 — McMap. All rights reserved.