Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.util.Log;

public class Main {
    private static String TAG = "HotspotDbHelper";
    private static double LATLON_SECTION = 0.044966;
    private static double LATLON_SECTION_EDGE = 0.2;

    public static String generateHashWhereClause(double lat, double lng) {
        double latHash = (lat + 180) / LATLON_SECTION;
        double lngHash = (lng + 180) / LATLON_SECTION;
        int latHashRounded = (int) Math.round(latHash);
        int lngHashRounded = (int) Math.round(lngHash);

        int iHash = getHash(latHashRounded, lngHashRounded);
        String whereClause = "hash = " + iHash;

        int nearbyLat = 0;
        int nearbyLng = 0;
        double overlap = LATLON_SECTION_EDGE;
        if (Math.abs(latHash - latHashRounded) > (0.5 - overlap))
            nearbyLat = (int) Math.signum(latHash - latHashRounded);

        if (Math.abs(lngHash - lngHashRounded) > (0.5 - overlap))
            nearbyLng = (int) Math.signum(lngHash - lngHashRounded);

        if (nearbyLat != 0)
            whereClause += " OR hash = " + getHash(latHashRounded + nearbyLat, lngHashRounded);
        if (nearbyLng != 0)
            whereClause += " OR hash = " + getHash(latHashRounded, lngHashRounded + nearbyLng);
        if ((nearbyLat != 0) && (nearbyLng != 0))
            whereClause += " OR hash = " + getHash(latHashRounded + nearbyLat, lngHashRounded + nearbyLng);

        Log.d(TAG,
                "HotspotDbHelper generateHashWhereClause lat: " + lat + " lon: " + lng + " Where: " + whereClause);
        return whereClause;
    }

    private static int getHash(int latHashRounded, int lngHashRounded) {
        return latHashRounded * 10000 + lngHashRounded;
    }
}