I'm using angular google maps and need help getting the new bounds changed from the event fired

自古美人都是妖i 提交于 2020-01-14 05:17:09

问题


This is my current code which is called when bounds are changed and works:

 scope.boundsChanged= function(arg){
       console.log(arg);                       
 };

I basically need the new array of lat and lng when this function above is called. I'm unsure are the retrieve it.

I'm using angular version 1 with JavaScript in a directive using a templateUrl.

Img of console log of bounds arg:


回答1:


I dont know exactly what is returned in the boundsChanged() function, but assuming changed bounds are returned in the function, method is the same to get lat, lng coordinates:

scope.boundsChanged= function(arg){

    //assuming changed bounds is returned as the 'arg'
    var polygonBounds = arg;
    var coordinates = [];

    for (var i = 0; i < polygonBounds.length; i++)
    {
        coordinates.push({lat: polygonBounds.getAt(i).lat(), lng: polygonBounds.getAt(i).lng()});
        coordinates.push(new google.maps.LatLng(polygonBounds.getAt(i).lat(), polygonBounds.getAt(i).lng()));
    }

   console.log(arg);                       
};


来源:https://stackoverflow.com/questions/36447127/im-using-angular-google-maps-and-need-help-getting-the-new-bounds-changed-from

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!