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)
Thanks for sharing -
ReplyDeleteHistogram Grayscale opencv python
how to insert unicode characters in mysql using php
how to display PDF in HTML using Javascript
Histogram Equalization OpenCV
Matplotlib pie chart
Password hash and verify in PHP