我使用下面的代码来获取经纬度。长。通过提供MCC,MNC 我正在使用Google Maps地理位置API,但对于不同的MCC/MNC值,我得到了相同的结果(纬度/经度)。即使当我要求空白json时,我也会得到相同的结果(lat/long)。 我哪里错了?使用谷歌地图地理定位API
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();
}
}
同时在“callID”的拼写中存在错误,它应该是callId。 – Tushar