Google maps api 3 在GMAPAPIv3中绘制一个按缩放级别缩放的矩形

Google maps api 3 在GMAPAPIv3中绘制一个按缩放级别缩放的矩形,google-maps-api-3,Google Maps Api 3,目前,我有一个函数,它用以下代码绘制了一个大约2公里大的矩形: var radius = 0.02; var c = Math.cos(location.lat()* Math.PI / 180); rectangle.setBounds(new google.maps.LatLngBounds( new google.maps.LatLng(location.lat()-c*radius/2, location.lng()-radius/

目前,我有一个函数,它用以下代码绘制了一个大约2公里大的矩形:

var radius = 0.02;
        var c = Math.cos(location.lat()* Math.PI / 180);
        rectangle.setBounds(new google.maps.LatLngBounds(
            new google.maps.LatLng(location.lat()-c*radius/2, location.lng()-radius/2),
            new google.maps.LatLng(location.lat()+c*radius/2, location.lng()+radius/2)));

        rectangle.setMap(map);
在缩放级别1,矩形太小,在缩放级别18,矩形太宽


我更希望矩形大小是贴图大小的百分比,以便在创建时无论缩放级别如何都始终可见。你能帮我找到关于如何实现它的信息吗?

编辑:我找到了一个解决方案:

var scale = Math.pow(2,map.getZoom());

        rectangle.setBounds(new google.maps.LatLngBounds(
            new google.maps.LatLng(((location.lat()* scale) - 50)/ scale, ((location.lng()* scale) - 75)/ scale),
            new google.maps.LatLng(((location.lat()* scale) + 50)/ scale, ((location.lng()* scale) + 75)/ scale)));

        rectangle.setMap(map);

如果对其他人有用,请将您的解决方案作为答案发布。