javascript - Restricting panning to one globe in Google Maps API -


i have map created using google maps api, , i'd restrict panning 1 globe; default can pan continuously east/west, map repeats endlessly. i'm trying use henningj's solution posted this question

var allowedbounds = new google.maps.latlngbounds(     new google.maps.latlng(85, -180),     new google.maps.latlng(-85, 180) ); lastvalidcenter = map.getcenter();  google.maps.event.addlistener(map, "center_changed", function() {     if (allowedbounds.contains(map.getcenter())) {         lastvalidcenter = map.getcenter();         return;      }      map.panto(lastvalidcenter); }); 

what have allows no panning whatsoever, call 'contains' fails. if log map.getcenter() looks sensible enough, think(?!):

object { a: 54.683366, f: 25.31663500000002 } 

can see i'm doing wrong?

you have allowedbounds defined incorrectly. should (from the documentation):

latlngbounds(sw?:latlng, ne?:latlng) constructs rectangle points @ south-west , north-east corners.

this:

var allowedbounds = new google.maps.latlngbounds(     new google.maps.latlng(85, -180),     new google.maps.latlng(-85, 180) ); 

should be:

var allowedbounds = new google.maps.latlngbounds(     new google.maps.latlng(-85, -180),  //sw     new google.maps.latlng(85, 180)     //ne );  

(negative longitudes west of positive ones, negative latitudes south of positive ones)

proof of concept fiddle


Comments

Post a Comment

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -