Example usage for com.google.common.geometry S2LatLng fromRadians

List of usage examples for com.google.common.geometry S2LatLng fromRadians

Introduction

In this page you can find the example usage for com.google.common.geometry S2LatLng fromRadians.

Prototype

public static S2LatLng fromRadians(double latRadians, double lngRadians) 

Source Link

Usage

From source file:com.norman0406.slimgress.API.Game.GameState.java

public void intLoadCommunication(final double radiusKM, final boolean factionOnly, final Handler handler) {
    try {/* w  w w  .  j a  va 2s  .com*/
        checkInterface();

        final double earthKM = 2 * Math.PI * 6371; // circumference

        S2LatLng center = S2LatLng.fromE6(mLocation.getLatitude(), mLocation.getLongitude());
        S2LatLng size = S2LatLng.fromRadians((Math.PI / earthKM) * radiusKM,
                (2 * Math.PI / earthKM) * radiusKM);
        S2LatLngRect region = S2LatLngRect.fromCenterSize(center, size);

        // get cell ids for area
        String[] cellIds = Utils.getCellIdsFromRegion(region, 8, 12);

        // create cells
        JSONArray cellsAsHex = new JSONArray();
        for (int i = 0; i < cellIds.length; i++)
            cellsAsHex.put(cellIds[i]);

        // create params
        JSONObject params = new JSONObject();
        params.put("cellsAsHex", cellsAsHex);
        params.put("minTimestampMs", -1);
        params.put("maxTimestampMs", -1);
        params.put("desiredNumItems", 50);
        params.put("factionOnly", factionOnly);
        params.put("ascendingTimestampOrder", false);

        mInterface.request(mHandshake, "playerUndecorated/getPaginatedPlexts", mLocation, params,
                new RequestResult(handler) {
                    @Override
                    public void handleResult(JSONArray result) {
                        try {
                            // add plexts
                            for (int i = 0; i < result.length(); i++) {
                                PlextBase newPlext = PlextBase.createByJSON(result.getJSONArray(i));
                                mPlexts.add(newPlext);
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });
    } catch (JSONException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}