-1

I'm currently learning to use google maps and am following the following to set a max bound for my map: Google Maps v3 - limit viewable area and zoom level

My bounds are set as:

var strictBounds = new google.maps.LatLngBounds(
  new google.maps.LatLng(41.600, -87.857),
  new google.maps.LatLng(42.065, -87.310)
)

Within my dragend event listener, I console.log(strictBounds) and am getting the following:

Google Maps strictBounds return

It is returning my south-west Latitude and north-east Latitude together as one LatLng and my south-west Longitude and north-east Longitude as one LatLng.

I could sorta hack it and set south-west and north-east coordinates so that the return would be what I want it to be, but I was wondering why this is happening in this scenario and would I be running into this problem further with other google map methods?

EDIT:

Just to clarify, my two LatLng positions set in strictBounds should be my southWest and northEast positions for the max bounds of the map.

When I use the addListener method provided in the link above (Google Maps v3 - limit viewable area and zoom level), it grabs the wrong lat/long from strictBounds.

Instead of grabbing: (41.6, -87.857), (42.065, -87.310)

It grabs: (41.6, 42.065), (-87.31, -87.856999..)

Community
  • 1
  • 1
philip yoo
  • 2,462
  • 5
  • 22
  • 37
  • Possible duplicate of [How to deal with floating point number precision in JavaScript?](http://stackoverflow.com/questions/1458633/how-to-deal-with-floating-point-number-precision-in-javascript) – Jaromanda X Nov 10 '15 at 00:38
  • I don't think this has anything to do with the floating point. The floating point number is still acceptable for the longitude or latitude. What I'm asking is why when I set my `strictBounds`, the Latitude for both north and south are set together and the Longitude for both west and east are set together. This will then lead my map view to some location around Latitude 41.6 and Longitude 42.065 – philip yoo Nov 10 '15 at 01:14

1 Answers1

1

The way you define the bound is correct. Just don't use console.log(strictBounds). Use the following instead

var sw = strictBounds.getSouthWest();
var ne = strictBounds.getNorthEast();

console.log(sw.lat() + "," + sw.lng());
console.log(ne.lat() + "," + ne.lng());
Byron Singh
  • 1,408
  • 1
  • 13
  • 15