google map automatically zooms one out when getting bounds from session

google map automatically zooms one out when getting bounds from session

I work on a google map where I try to make the map remember the bounds when refreshing.

In order to remember the coordinates, I use the following procedure.

The function that saves the bounds.

function saveKoordinates(bounds)



urlCall = libraryRoot+"/jscalls/rememberBounds.php?type=koordinates&sw="+bounds.getSouthWest()+"&ne="+bounds.getNorthEast()+"&center="+bounds.getCenter()+"&zoom="+map.getZoom();

$.getJSON(urlCall, function(data){








The ajax file on the server

$koordinates['center'] = $_GET["center"];

$koordinates['zoom'] = $_GET["zoom"];

$koordinates['sw'] = $_GET["sw"];

$koordinates['ne'] = $_GET["ne"];

When the map is reloaded



//The values have to be extracted from the session array and

var lastzoom='<?php echo $_SESSION["koordinates"]['zoom'];?>';

var lastne='<?php echo $_SESSION["koordinates"]['ne'];?>';

var lastsw='<?php echo $_SESSION["koordinates"]['sw'];?>';

var lastcenter='<?php echo $_SESSION["koordinates"]['center'];?>';

var lastnestring=lastne.replace('(', '');

lastnestring=lastnestring.replace(')', '');

var lastnearray = lastnestring.split(',');

var lastswstring=lastsw.replace('(', '');

lastswstring=lastswstring.replace(')', '');

var lastswarray = lastswstring.split(',');

var lastcenterstring=lastcenter.replace('(', '');

lastscentertring=lastcenterstring.replace(')', '');

var lastcenterarray = lastcenterstring.split(',');

//and casted into float value

var neLat=parseFloat(lastnearray[0]);var neLng=parseFloat(lastnearray[1]);

var swLat=parseFloat(lastswarray[0]);var swLng=parseFloat(lastswarray[1]);

bounds = new google.maps.LatLngBounds();

bounds.extend(new google.maps.LatLng(neLat,neLng));

bounds.extend(new google.maps.LatLng(swLat,swLng));

When I debug, via console.log() I can see that the the map remembers the values. So far so good.

But the problem is that in spite of having the same bounds it zooms out one level when the map is reloaded.

The weird thing is that when I hardcode the latitude and longitude of northeast and southwest, the map does not zoom out one level.

So when I generate the the bounds this way:

bounds.extend(new google.maps.LatLng(neLat,neLng));

bounds.extend(new google.maps.LatLng(swLat,swLng));

it zooms out one level but not when I generate the values this way:

bounds.extend(new google.maps.LatLng('55.46185555786109','8.9049453012085'));

bounds.extend(new google.maps.LatLng('55.501446631515286','9.139434742126468'));

I have experimented with the data types, but I have also made a version where the values are saved and loaded as single parameters (one session for each latitude and longitude) but it did not solve the problem.

I use version 3.18 for google map