2015-02-24 75 views
0

,我收到了谷歌地图的当前范围扩大的LatLngBounds盒致电:如何使用经纬度数据

map.getBounds() 

这将返回的LatLngBounds。例如:

((-26.574013562724005, -1.5375947819336488), (-25.230016040794602, 3.735842718066351)) 

是否有可能得到新的经纬度点,如果我想围绕地图的中心百分比(例如1%),以增加地图界限。

我试着乘以1.01的每个坐标,但是这会改变地图而不会增加边界。

我想使用增加的框大小来启动缓存标记,以便在用户平移或缩小时保存对服务器的调用。

下图将会更好地解释需要采取什么措施:

enter image description here

+0

简单的方法是通过减小缩放级别一个('map.setZoom(map.getZoom() - 1)'),除非你只是试图绘制一个代表地图上边界的框。 – geocodezip 2015-02-24 19:55:21

+0

我不想减小缩放级别,我想开始加载缓存当前范围外的标记。 – Morne 2015-02-24 19:57:14

+0

请在你的问题中澄清。 – geocodezip 2015-02-24 19:58:31

回答

2

基于markerclusterergetExtendedBounds功能,你可以用这一个:

function getExtendedBounds(map, overlay) { 
    //With _mapBoundsEnlargePixels we add some extra space surrounding the map 
    //change this value until you get the desired size 
    var _mapBoundsEnlargePixels = 500; 

    var projection = overlay.getProjection(); 
    var bounds = angular.copy(map.getBounds()); 

    // Turn the bounds into latlng. 
    var tr = new google.maps.LatLng(bounds.getNorthEast().lat(), 
     bounds.getNorthEast().lng()); 
    var bl = new google.maps.LatLng(bounds.getSouthWest().lat(), 
     bounds.getSouthWest().lng()); 

    // Convert the points to pixels and extend out 
    var trPix = projection.fromLatLngToDivPixel(tr); 
    trPix.x = trPix.x + _mapBoundsEnlargePixels; 
    trPix.y = trPix.y - _mapBoundsEnlargePixels; 

    var blPix = projection.fromLatLngToDivPixel(bl); 
    blPix.x = blPix.x - _mapBoundsEnlargePixels; 
    blPix.y = blPix.y + _mapBoundsEnlargePixels; 

    // Convert the pixel points back to LatLng 
    var ne = projection.fromDivPixelToLatLng(trPix); 
    var sw = projection.fromDivPixelToLatLng(blPix); 

    // Extend the bounds to contain the new bounds. 
    bounds.extend(ne); 
    bounds.extend(sw); 

    return bounds; 
} 
+0

我最终采取了一种完全不同的方法,但这个答案仍然有用。谢谢! – Morne 2015-02-26 08:07:31

+1

如果你分享了你的方法,那将会很棒。 – 2016-10-05 13:34:56

+0

是的,会对你的方法感兴趣,@Morne – xsonic 2016-11-17 15:30:10