0
<!DOCTYPE html>
<html>
<head>
<title>Google Maps JavaScript API v3 Example: Map Simple</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta charset="UTF-8">
<style type="text/css">
#map_canvas {
    width: 500px;
    height: 500px;
}
</style>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=geometry"></script>
<script type="text/javascript">
    var map;
    function initialize() {
        var myOptions = {
            zoom : 8,
            center : new google.maps.LatLng(-34.397, 150.644),
            mapTypeId : google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);

        var locationA = {
            latitude : 37.788081 + 0.0049,
            longitude : -83.001709 + 0.00019
        };
        var locationB = {
            latitude : 37.788081,
            longitude : -83.001709
        };

        var sw = new google.maps.LatLng(locationA.latitude, locationA.longitude);
        var ne = new google.maps.LatLng(locationB.latitude, locationB.longitude);

        var distance = google.maps.geometry.spherical.computeDistanceBetween(sw, ne);
        console.log("Distance between SW & NE: " + distance);

        var bounds = new google.maps.LatLngBounds(sw, ne);
        console.log(bounds);
        map.fitBounds(bounds);
    }

    google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
    <div id="map_canvas"></div>
</body>
</html>

The above returns this: enter image description here

Got it by accident during dev tests, cleaned everything around that "bug" and still, it really seems to be a bug.

Can anyone explain it?

Setting locationA.longitude's 0.00019 to 0 does show valid map so this is the very issue.

Poni
  • 11,061
  • 25
  • 80
  • 121
  • BTW, if you debug you'll notice that `bounds` gets wrong values. It's an issue with its constructor. – Poni Jul 24 '12 at 22:57

1 Answers1

1

Your bounds is invalid, south is greater than north and east is greater than west. If you switch the pluses to minus it will load. I would just create a LatLngBounds with no arguments and use bounds.extend instead.

var bounds = new google.maps.LatLngBounds();
    bounds.extend(sw);
    bounds.extend(ne);
puckhead
  • 1,881
  • 15
  • 10