On Jul 14, 4:07 am, Rossko <
ros...@culzean.clara.co.uk> wrote:
> > I've got a simple map and I want to set it's exact bounds.
>
> You can't ; zoom is only available in integer levels, so a map of
> fixed viewing pane size cannot be exactly fitted to any particular
> bounds. Then there's the issue of proportions ; if your bounds were
> square and the viewport rectangular an exact fit cannot be achieved.
> "Square" is itself pretty meaningless here, due to looking at a curved
> world's surface through the distortion of Mercator's projection.
>
> The fitBounds method does what it can to give a map view that
> _includes_ the given bounds, but usually includes a bit more too.
> What you see is how it is intended to work.
Thanks for your reply. I'm aware that the map has zoom levels and no
continuous zoom and you are right, that I can not expect it to
'accept'
all of my bounds that I specify. But what I find strange is, that
the call
map.fitBounds( map.getBounds())
changes the bounds. In my opinion the fit bounds method wouldn't have
to do anything.
I also disabled the UI with "disableDefaultUI: true" in
MapOptions, because the documentation of the other possible method
Map.panToBounds() says: "The bounds will be positioned inside the area
bounded by the map type and navigation controls, if they are present
on
the map.".
Further investigations show that even if I shrink the bounds before
applying them to the map with fitBounds() the map will move south:
Instead of a simple
map.fitBounds( map.getBounds())
I'm doing a shrinking of the bounds before reapplying them:
var bounds = map.getBounds();
var ne = bounds.getNorthEast();
var sw = bounds.getSouthWest();
var k = 5.0;
var n = ne.lat() - k;
var e = ne.lng() - k;
var s = sw.lat() + k;
var w = sw.lng() + k;
var neNew = new google.maps.LatLng( n, e );
var swNew = new google.maps.LatLng( s, w );
var boundsNew = new google.maps.LatLngBounds( swNew, neNew );
qlog( "bo=" + bounds.toUrlValue() );
qlog( "bn=" + boundsNew.toUrlValue() );
map.fitBounds( boundsNew );
If I look at the log I get:
log:bounds are: 34.931422,28.897984,57.63981,49.772008
log:bo=34.931422,28.897984,57.63981,49.772008
log:bn=39.931422,33.897984,52.63981,44.772008
log:bounds_changed_listerner: 33.916404,28.897984,56.975181,49.772008
log:bo=33.916404,28.897984,56.975181,49.772008
log:bn=38.916404,33.897984,51.975181,44.772008
log:bounds_changed_listerner: 32.914338,28.897984,56.315118,49.772008
log:bo=32.914338,28.897984,56.315118,49.772008
log:bn=37.914338,33.897984,51.315118,44.772008
log:bounds_changed_listerner: 31.92558,28.897984,55.659918,49.772008
log:bo=31.92558,28.897984,55.659918,49.772008
log:bn=36.92558,33.897984,50.659918,44.772008
log:bounds_changed_listerner: 30.950443,28.897984,55.00986,49.772008
log:bo=30.950443,28.897984,55.00986,49.772008
log:bn=35.950443,33.897984,50.00986,44.772008
log:bounds_changed_listerner: 29.989199,28.897984,54.3652,49.772008
log:bo=29.989199,28.897984,54.3652,49.772008
log:bn=34.989199,33.897984,49.3652,44.772008
log:bounds_changed_listerner: 29.042078,28.897984,53.72618,49.772008
log:bo=29.042078,28.897984,53.72618,49.772008
log:bn=34.042078,33.897984,48.72618,44.772008
log:bounds_changed_listerner: 28.109274,28.897984,53.09302,49.772008
log:bo=28.109274,28.897984,53.09302,49.772008
log:bn=33.109274,33.897984,48.09302,44.772008
log:bounds_changed_listerner: 27.190946,28.897984,52.465925,49.772008
log:bo=27.190946,28.897984,52.465925,49.772008
log:bn=32.190946,33.897984,47.465925,44.772008
log:bounds_changed_listerner: 26.287218,28.897984,51.845083,49.772008
As you can see, the east and west coordinates stay the same, but the
north
and south coordinates move slowly south.
I guess, there's not a lot that one can do... but if anyone has
another idea? :-)
Best regards,
Klaas.