ad...@svk-zw.de
unread,Oct 6, 2010, 4:57:23 AM10/6/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Google Maps JavaScript API v3
Hey there,
I' ve searched the hole web, but I think I am not good enough in most
script languages.
What I need is a program where I can entere the center-coordinates of
the google map tile, and the wanted zoom level. The program has to
calculate the gps coordinates of 2 corners (bsp. Upper-left, lower-
right) and give them back.
Example [ullong, ullat, lrlong, lrlat] = gpscorners(long, lat,
zoomelevel)
I've found this one here, but I don't know how to use it.
import java.applet.*;
import java.awt.*;
import java.lang.*;
public class Googlecoordinates
{
/**
* returns a Rectangle2D with x = lon degrees , y = lat degrees,
* width=lonSpan, height=latSpan
* for an x,y,zoom as used by google.
*/
public static Rectangle2D.Double getLatLong(int x, int y, int
zoom)
{
double lon = -180; // x
double lonWidth = 360; // width 360
//double lat = -90; // y
//double latHeight = 180; // height 180
double lat = -1;
double latHeight = 2;
int tilesAtThisZoom = 1 << (17 - zoom);
lonWidth = 360.0 / tilesAtThisZoom;
lon = -180 + (x * lonWidth);
latHeight = -2.0 / tilesAtThisZoom;
lat = 1 + (y * latHeight);
// convert lat and latHeight to degrees in a mercator
projection
// note that in fact the coordinates go from
// about -85 to +85 not -90 to 90!
latHeight += lat;
latHeight = (2 * Math.atan(Math.exp(Math.PI * latHeight))) -
(Math.PI / 2);
latHeight *= (180 / Math.PI);
lat = (2 * Math.atan(Math.exp(Math.PI * lat))) - (Math.PI / 2);
lat *= (180 / Math.PI);
latHeight -= lat;
if (lonWidth < 0) {
lon = lon + lonWidth;
lonWidth = -lonWidth;
}
if (latHeight < 0) {
lat = lat + latHeight;
latHeight = -latHeight;
}
return new Rectangle2D.Double(lon, lat, lonWidth, latHeight);
}
}
Hope you can help me. Thanks for your time!