I used the google gears location API, in order to locate cell-id and wifi mac addresses (get latitude/longitude). But not using a browser, using java code. I used this URI: http://www.google.com/loc/json
Now, this API is no more available!! --> https://developers.google.com/gears/
I unterstand that the replacement is HTML5, but my application dosen't run on a browser... Do you know how I can use the HTML5 API without browser (simply HTTP request), or an alternative?
Here is my old code, for information:
...
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;
}
}
Google now offers a paid Geolocation API https://developers.google.com/maps/documentation/business/geolocation/