4

次のコードを使用して緯度を取得しています。長いです。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();

    }

}
4

2 に答える 2

1

JSON リクエスト オブジェクトは完成していますか? つまり、使用しているキーは単一の「タワー」記述の一部であるように見えますが、これはより大きなリクエスト本文の一部にすぎず、次のようにフォーマットする必要があります。

{
  "homeMobileCountryCode": 310,
  "homeMobileNetworkCode": 410,
  "radioType": "gsm",
  "carrier": "Vodafone",
  "cellTowers": [
   // See the Cell Tower Objects section below.
  ],
  "wifiAccessPoints": [
    // See the WiFi Access Point Objects section below.
  ]
}

タワー オブジェクトは次のようにフォーマットされます。

{'cellTowers': [
  {
    'cellId': 42,
    'locationAreaCode': 415,
    'mobileCountryCode': 310,
    'mobileNetworkCode': 410,
    'age': 0,
    'signalStrength': -60,
    'timingAdvance': 15
  }
]}

あなたのjsonオブジェクトが完全なものに変わる方法を見逃していると思いますか?

https://developers.google.com/maps/documentation/business/geolocation/

于 2013-07-22T18:06:38.057 に答える