Example usage for com.google.common.geometry S2LatLngRect fromCenterSize

List of usage examples for com.google.common.geometry S2LatLngRect fromCenterSize

Introduction

In this page you can find the example usage for com.google.common.geometry S2LatLngRect fromCenterSize.

Prototype

public static S2LatLngRect fromCenterSize(S2LatLng center, S2LatLng size) 

Source Link

Document

Construct a rectangle from a center point (in lat-lng space) and size in each dimension.

Usage

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

public void intLoadCommunication(final double radiusKM, final boolean factionOnly, final Handler handler) {
    try {/*from  w w  w.j av a2 s  . 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();
    }
}