Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps Geolocation API only ever returning location of 1st tower in my array

I'm trying to make use of the Google Maps Geolocation API. I'm POST-ing a JSON file only containing cell towers to https://www.googleapis.com/geolocation/v1/geolocate?key=MYKEY.

Example JSON:

{
    "cellTowers":[
    {
        "cellId":65535,
        "locationAreaCode":5160,
        "mobileCountryCode":234,
        "mobileNetworkCode":10,
        "signalStrength":-53
    },
    {
        "cellId":34177,
        "locationAreaCode":5160,
        "mobileCountryCode":234,
        "mobileNetworkCode":10,
        "signalStrength":-55
    }
]}

This has been validated correct JSON. I'm however having issues getting decent data back from the API.

I've implemented the POST in Java using the Apache HTTPClient & HTTPPost libraries. I get a valid response back, but it's always the LAT,LNG of the first cell tower in the cellTowers array. As if the API is reading the first cell tower, getting the location then ignoring the rest. Of course I've validated that this is the behavior by reversing and shuffling the list and the response changes each time to the first towers location. Here's my code:

HttpParams httpParams = new BasicHttpParams();
ConnRouteParams.setDefaultProxy(httpParams, new HttpHost(PROXY_HOST, PROXY_PORT));
HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT_MILLISEC);
HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC);

HttpClient client = new DefaultHttpClient(httpParams);
HttpPost request = new HttpPost(GOOGLE_GEOLOCATION_API);
request.setHeader("Content-type", "application/json");

try {
    StringEntity se = new StringEntity(json);
    request.setEntity(se);

    HttpResponse response = client.execute(request);
    if(response!=null){
        String jsonResult = EntityUtils.toString(response.getEntity());
        GeolocationResponse geolocationResponse = gson.fromJson(jsonResult, GeolocationResponse.class);

        logger.info(jsonResult);
        logger.info("Est. Location: " + geolocationResponse.toString());
    }
} catch (Exception e) {
    e.printStackTrace();
}

Does the Geolocation API only support one cell tower at a time? I thought that it would be more clever than this, using some sort of signal propagation and distance estimation across all the towers.

like image 994
axle_h Avatar asked Oct 22 '22 20:10

axle_h


2 Answers

In a recent communication with Google about our mapping API subscription, I asked for some general info on the Geo-location API. Turns out it doesn't do any complex triangulation of cell tower signals.

like image 56
axle_h Avatar answered Oct 31 '22 12:10

axle_h


They just use the first one considered valid. Reference: http://code.google.com/p/gmaps-api-issues/issues/detail?id=6929

like image 31
carlosms Avatar answered Oct 31 '22 13:10

carlosms