Hi everybody!
I am having trouble calculating the best zoom level for a given
MaxLat, MinLat, MaxLng, MinLng values.
I found this javascript code through this group, which I translated
into Java (my server-side programming language). The problem is with
the scale, that doesn't work well.
Could you give me any ideas of a good algorithm? Thank you in advance
for your help.
-------------------------------------------------------------------------
double minLong = 999;
double maxLong = -999;
double minLat = 999;
double maxLat = -999;
//Get the default map width
int width = getWidth();
int height = getHeight();
int scale = getScale().intValue());
// Figure out the elemental unit (depends on the size of the map)
// You will need to re-run resizeMap() if the size of the map changes.
if ( scale > 0 ) {
width /= Math.pow( 2, scale );
height /= Math.pow( 2, scale );
}
// Find the max/min points
for(Situation s : situations){
if(s.getLng().intValue() < minLong){
minLong = s.getLng().intValue();
}
if(s.getLng().intValue() > maxLong){
maxLong = s.getLng().intValue();
}
if(s.getLat().intValue() < minLat){
minLat = s.getLat().intValue();
}
if(s.getLat().intValue() > maxLat){
maxLat = s.getLat().intValue();
}
}
// Find the optimal Width Zoom
int wZoom = 0;
double w = Math.abs( maxLong - minLong );
for (int i = 1; i < 16; i++ ) {
if ( width > w ) break;
width *= 2;
wZoom = i;
}
// Find the optimal Height Zoom
int hZoom = 0;
double h = Math.abs( maxLat - minLat );
for ( int i = 1; i < 16; i++ ) {
if ( height > h ) break;
height *= 2;
hZoom = i;
}
double centerLat = (minLat + maxLat)/2; //GOOD!!!
double centerLng = (minLong + maxLong)/2; //GOOD!!!
int optimalScale = wZoom > hZoom ? wZoom : hZoom; //BAD :-(
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---