Sunday, 31 May 2015

googlemap bounds controll

To control google map boundary, you should use google.maps.LatLngBounds After map pans(users drag and drop to move map) , we should verify if new map center is still in the bound.

Below link shows world map boundary:

var strictBounds = new google.maps.LatLngBounds(
    new google.maps.LatLng(85, -180),           // top left corner of map
    new google.maps.LatLng(-85, 180)            // bottom right corner

However if you use this bounds to verify it's center, like this:


You will get "false".

Blow blog also mentioned this issue:

I finally realise that,  the constructor of LatLngBounds() use south-west and north-east corners:

No comments:

Post a comment