替换Google齿轮位置API

时间:2012-11-29 10:14:24

标签: api location cell gears

我使用谷歌齿轮位置API,以找到cell-id和wifi mac地址(获取纬度/经度)。但是没有使用浏览器,使用java代码。我使用了这个URI:http://www.google.com/loc/json

现在,这个API已不再可用!! - > https://developers.google.com/gears/

我想知道替代品是HTML5,但我的应用程序不能在浏览器上运行......你知道如何在没有浏览器的情况下使用HTML5 API(只是HTTP请求),还是替代?

以下是我的旧代码,供参考:

...
        JSONObject root = new JSONObject();

        root.put("version", "1.1.0");   

        root.put("host", "maps.google.com");

        JSONArray cell_towers = new JSONArray();
        JSONObject cell_tower = new JSONObject();
        cell_tower.put("cell_id", 10104);
        cell_tower.put("location_area_code", 101);
        cell_tower.put("mobile_country_code", 228);
        cell_tower.put("mobile_network_code", 1);
        cell_tower.put("request_address", true);
        cell_tower.put("address_language", "en_GB");
        cell_tower.put("age", new Integer(0));
        cell_towers.put(cell_tower);
        root.put("cell_towers", cell_towers);

        String result = postHttp("http://www.google.com/loc/json", root);
    }

...

    private static String postHttp(String urlToUse, JSONObject data) throws Exception {

        StringBuilder respBuilder = new StringBuilder();
        if (urlToUse.length() == 0) {
            return null;
        }
        URL url;
        try {
            url = new URL(urlToUse);
        } catch (MalformedURLException ex) {
            return null;
        }
        URLConnection urlCon;
        try {
            urlCon = url.openConnection();

            urlCon.setDoOutput(true);
            OutputStream wr = urlCon.getOutputStream();
            if (data != null) {
                String dd = data.toString();
                wr.write(dd.getBytes());
            }
            wr.flush();
            int len = urlCon.getContentLength();
            if (len != 0) {

                BufferedReader reader = new BufferedReader(new InputStreamReader(urlCon.getInputStream(), "UTF-8"));

                String line="";
                while ((line = reader.readLine()) != null) {
                    respBuilder.append(line + "\n");
                }
                return respBuilder.toString().trim();
            } else {
                return null;
            }
        } catch (IOException ex) {
            return null;
        }
    }

2 个答案:

答案 0 :(得分:2)

答案 1 :(得分:-1)

你可以拨打[minigps]:http://www.minigps.net/map.html"点击查询" 可以使用google json api,只将ip更改为:http://www.minigps.net/minigps/map/google/location

fllow是http字节: 这是这样,但现在遵循代码块:

   URL:http://www.minigps.net/minigps/map/google/location
   Request Method:POST
   Status Code:200 OK
   Request Headersview source
   Accept:application/json, text/javascript, */*; q=0.01
   Accept-Charset:GBK,utf-8;q=0.7,*;q=0.3
   Accept-Encoding:gzip,deflate,sdch
   Accept-Language:zh-CN,zh;q=0.8
   Connection:keep-alive
   Content-Length:191
   Content-Type:application/json; charset=UTF-8
   Cookie:bdshare_firstime=1356366713546; JSESSIONID=68243935CD3355089CF07A3A22AAB372
   Host:www.minigps.net
   Origin:http://www.minigps.net
   Referer:http://www.minigps.net/map.html
   User-Agent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.4 (KHTML, like Gecko)            Chrome/22.0.1229.94 Safari/537.4
   X-Requested-With:XMLHttpRequest
   Request Payload
   {"version":"1.1.0","host":"maps.google.com","cell_towers":  [{"cell_id":"3721","location_area_code":"9779","mobile_country_code":"460","mobile_network_c       ode":"0","age":0,"signal_strength":-65}]}
    Response Headersview source
   Content-Type:application/json
   Date:Sat, 12 Jan 2013 06:03:15 GMT
   Server:Apache-Coyote/1.1
   Transfer-Encoding:chunked