我正在使用以下代码来获取纬度。长。通过提供 MCC、MNC,我为此使用了 Google Maps Geo-location API,但对于不同的 MCC/MNC 值,我得到了相同的结果(纬度/经度)。即使我请求空白 json,我也会得到相同的结果(纬度/经度)。我哪里错了?
public class CellID {
public static void main(String[] args) {
try{
putDataToServer("https://www.googleapis.com/geolocation/v1/geolocate?key=mykey",null);
}
catch(Throwable throwable){
System.out.println("Error");
}
}
public static String putDataToServer(String url,JSONObject returnedJObject) throws Throwable
{
HttpPost request = new HttpPost(url);
JSONStringer json = (JSONStringer) new JSONStringer()
.object()
.key("mobileCountryCode").value(504)
.key("mobileNetworkCode").value(0)
.key("locationAreaCode").value(0)
.key("cellID").value(0)
.endObject();
System.out.println("json"+json.toString());
StringEntity entity = new StringEntity(json.toString(), "UTF-8");
request.setEntity(entity);
HttpResponse response =null;
HttpClient httpClient = new DefaultHttpClient();
try{
response = httpClient.execute(request);
}
catch(SocketException se)
{
throw se;
}
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
//Displaying the response received.
String line = "";
while ((line = rd.readLine()) != null) {
System.out.println(line);
if (line.startsWith("Auth=")) {
String key = line.substring(5);
// Do something with the key
}
}
return response.getEntity().toString();
}
}