我正在使用以下代码通过提供MCC和MNC来获取经纬度信息。我正在使用Google Maps地理位置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();
}
}