I'm using angular google maps and need help ge

2019-06-09 19:57发布

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:

enter image description here

1条回答
放荡不羁爱自由
2楼-- · 2019-06-09 20:20

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);                       
};
查看更多
登录 后发表回答