मैं के रूप में यहां प्रदर्शन किया पैन सीमा व्यवहार को पुन: कोशिश कर रहा हूँ:, http://econym.org.uk/gmap/example_range.htmगूगल मैप्स: सीमा पैनिंग
दुर्भाग्य से, यह एपीआई संस्करण 2 उपयोग कर रहा है वर्तमान संस्करण के बजाय 3. मैं आदेशों को अद्यतन करने कर रहा हूँ इतना है कि वे वर्तमान हैं, लेकिन मैं क्योंकि यह काम नहीं कर रहा मैं कुछ छूट गया हो सकता है लगता है:
<html>
<body>
<script type="text/javascript" src="http://meyouand.us/scripts/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
$(document).ready(function() {
// Generate map
var latlng = new google.maps.LatLng(37.76201, -122.4375);
var myOptions = { zoom: 12, center: latlng, panControl: false, zoomControl: true, mapTypeControl: false, streetViewControl: false, scrollwheel: true, draggable: true, mapTypeId: google.maps.MapTypeId.TERRAIN };
var map = new google.maps.Map(document.getElementById("gmap"), myOptions);
// Limit panning
// The allowed region which the whole map must be within
var southWest = new google.maps.LatLng(37.684, -122.591);
var northEast = new google.maps.LatLng(37.836, -122.333);
var allowedBounds = new google.maps.LatLngBounds(southWest, northEast);
// Double check boundaries, plot points just in case
var sW = new google.maps.Marker({
position: southWest,
map: map,
title: "southWest"
});
var nE = new google.maps.Marker({
position: northEast,
map: map,
title: "northEast"
});
// Add a move listener to restrict the bounds range
google.maps.event.addListener(map, "dragend", function() { checkBounds(); });
// If the map position is out of range, move it back
function checkBounds() {
// Perform the check and return if OK
if (allowedBounds.contains(map.getCenter())) {
return;
}
// It's not OK, so find the nearest allowed point and move there
var C = map.getCenter();
var X = C.lng();
var Y = C.lat();
var AmaxX = allowedBounds.getNorthEast().lng();
var AmaxY = allowedBounds.getNorthEast().lat();
var AminX = allowedBounds.getSouthWest().lng();
var AminY = allowedBounds.getSouthWest().lat();
if (X < AminX) {X = AminX; alert('hi') }
if (X > AmaxX) {X = AmaxX; alert('hi') }
if (Y < AminY) {Y = AminY; alert('hi') }
if (Y > AmaxY) {Y = AmaxY; alert('hi') }
alert ("Restricting "+Y+" "+X);
map.setCenter(new LatLng(Y,X));
}
});
</script>
<body>
<div id="gmap" style="width: 480px; height: 440px;"></div>
</body>
</html>
चाहेंगे कोई मन आंखों का एक और सेट उधार अगर मैं कुछ छूट गया देखने के लिए? : डी
(स्टैक ओवरफ्लो पर एक और अद्यतित संस्करण 3 कोड है जिसे 'मैं Google मानचित्र एपीआई वी 3 में पैनिंग कैसे सीमित कर सकता हूं' कहा जाता है, हालांकि यह व्यवहार दृष्टि से परे आंदोलन को सीमित करने के बजाए वापस "स्नैप" करता है सीमाएं।)
इस पोस्ट का प्रयास करें: http://stackoverflow.com/questions/3818016/google-maps-v3-limit-viewable-area-and-zoom-level –