Skip to main content
 首页 » 编程设计

c#之在 google maps jquery 插件中定义一个区域

2024年01月13日31luoye11

我把这个插件放到我的网站上,我如何定义一个区域并限制访问者不能出门?

我没有权限 http://code.google.com出于政治原因。请帮我回答,不要提到那个!

提前致谢

请您参考如下方法:

以下示例会将 map 的平移限制在预定义的范围内,如果您打算这样做的话:

// Bounds for North America 
var allowedBounds = new GLatLngBounds(new GLatLng(48.19, -127.52),  
                                      new GLatLng(28.72, -68.81)); 
 
function checkBounds() {  
    if (allowedBounds.contains(map.getCenter())) { 
        return; 
    } 
 
    var c = map.getCenter(); 
    var x = c.lng(); 
    var y = c.lat(); 
    var maxX = allowedBounds.getNorthEast().lng(); 
    var maxY = allowedBounds.getNorthEast().lat(); 
    var minX = allowedBounds.getSouthWest().lng(); 
    var minY = allowedBounds.getSouthWest().lat(); 
 
    if (x < minX) { x = minX; } 
    if (x > maxX) { x = maxX; } 
    if (y < minY) { y = minY; } 
    if (y > maxY) { y = maxY; } 
 
    map.setCenter(new GLatLng(y, x)); 
} 
 
GEvent.addListener(map, "move", function() { checkBounds(); });