Search code examples
androidgoogle-maps-android-api-2tilegoogleio

Google IO 2013 App Mystery Values


I'm trying to make use of the SVGTileProvider that is found in the Google IO 2013 app. I can't figure out exactly how to position an image on the Google Map though. I've narrowed it down to this section of the class. These aren't lat/long coordinates however somehow they must be coming from lat/long coordinates. Does anyone know what these are or where they come from?

mBaseMatrix.setPolyToPoly(
    new float[]{
        0, 0,
        limits.width(), 0,
        limits.width(), limits.height()
    }, 0,
    new float[]{
        40.95635986328125f, 98.94217824936158f,
        40.95730018615723f, 98.94123077396628f,
        40.95791244506836f, 98.94186019897214f
    }, 0, 3);

Update

The first set of mystery numbers roughly translates to lat/long 37.783887,-122.405107.

Update 2

These methods help me convert latitude to a y value and vice versa. How can I do this for X and Longitude?

public static double y2lat(double aY) {
    return Math.toDegrees(2 * Math.atan(Math.exp(Math.toRadians(aY))) - Math.PI / 2);
}
public static double lat2y(double aLat) {
    return Math.toDegrees(Math.log(Math.tan(Math.PI / 4 + Math.toRadians(aLat) / 2)));
}

Solution

  • Turns out these are World Coordinates.

    Here is some java code to translate from lat/long to x/y.

    public static float lat2y(double aLat) {
        return (float) (((1 - Math.log(Math.tan(aLat * Math.PI / 180) + 1 / Math.cos(aLat * Math.PI / 180)) / Math.PI) / 2 * Math.pow(2, 0)) * 256);
    }
    public static float lon2x(double lon) {
        return (float) ((lon + 180f) / 360f * 256f);
    }