我使用下面的代碼來獲取經緯度。長。通過提供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