Hi there,
I'm making an application witch uses the Google Maps static api, i used the code example from the article:
Google Maps API in Java ME
My problem is that i have a list of waypoints in the format (lat,lng) and i need the get the position of the points on the static map in pixels... I tried to convert the code from the page that the article also links to(http://home.provide.net/~bratliff/adjust.js) but it dosn't work when i need to lat/lng to x/y...
here's my code that should do the same at adjust.js:
Code:
public static GPSPoint XYtoLL(GPSPoint mapCenter, int deltaX, int deltaY, int zoom){
return new GPSPoint(
YToL(LToY(mapCenter.getLat()) + (deltaY<<(21-zoom))),
XToL(LToX(mapCenter.getLng()) + (deltaX<<(21-zoom)))
);
}
public static Point LLtoXY(GPSPoint mapCenter, GPSPoint point, int zoom){
return new Point(
(int)round(Double.doubleToLongBits((LToX(point.getLng())-LToX(mapCenter.getLng()))) >> (21-zoom)),
(int)round(Double.doubleToLongBits((LToY(point.getLat())-LToY(mapCenter.getLat())))>>(21-zoom))
);
}
static double LToX(double x)
{
return round(offset + radius * x * Math.PI / 180);
}
static double LToY(double y)
{
return round(
offset - radius *
Double.longBitsToDouble(MicroDouble.log(
Double.doubleToLongBits(
(1 + Math.sin(y * Math.PI / 180))
/
(1 - Math.sin(y * Math.PI / 180))
)
)) / 2);
}
static double XToL(double x)
{
return ((round(x) - offset) / radius) * 180 / Math.PI;
}
static double YToL(double y)
{
return (Math.PI / 2 - 2 * Double.longBitsToDouble(
MicroDouble.atan(
MicroDouble.exp(Double.doubleToLongBits((round(y)-offset)/radius))
)
)) * 180 / Math.PI;
}
static double round(double num)
{
double floor = Math.floor(num);
if(num - floor >= 0.5)
return Math.ceil(num);
else
return floor;
}
GPSPoint consists of two doubles... (lat and lng)
the XYtoLL works perfekt... but the LLtoXY doesn't...
here's two results og the LLtoXY:
1. input LL: (57.69255211496328 | 10.51119089126587) out xy
-2147483349,-2147483383)
2. input LL: (57.54546006577498 | 10.32991647720337) out xy
-2147483349,-2147483383)
Can anyone tell me what I'm doing Wrong?