Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/440.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在谷歌地图上获取所有选定标记_Javascript_Angularjs_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 在谷歌地图上获取所有选定标记

Javascript 在谷歌地图上获取所有选定标记,javascript,angularjs,google-maps,google-maps-api-3,Javascript,Angularjs,Google Maps,Google Maps Api 3,我对选项有问题获取所有。这里是流程。 首先,当用户打开应用程序并想要选择位置时,他有角度谷歌地图,所有位置都用标记选择。此外,用户还链接了下拉列表选择(首先需要选择国家,我会在地图上显示该国家的所有标记,然后根据所选国家显示下一个下拉列表和所选国家的州,并仅显示该州的标记,城市也是如此。) 所有标记都有信息框,我将按钮添加到图表。当点击添加到图表时,我会在表格列表中显示带有标记id的信息 现在,我想让按钮获取全部并显示列表中的所有id。但是,根据所选下拉列表获取所有标记,例如,如果仅选择国家并按

我对选项有问题
获取所有
。这里是流程。

首先,当用户打开应用程序并想要选择位置时,他有
角度谷歌地图
,所有位置都用标记选择。此外,用户还链接了下拉列表选择(首先需要选择国家,我会在地图上显示该国家的所有标记,然后根据所选国家显示下一个下拉列表和所选国家的州,并仅显示该州的标记,城市也是如此。)

所有标记都有信息框,我将按钮
添加到图表
。当点击添加到图表时,我会在表格列表中显示带有标记id的信息

现在,我想让按钮获取全部并显示列表中的所有id。但是,根据所选下拉列表获取所有标记,例如,如果仅选择国家并按“获取全部”,我将获取国家中的所有标记列表,如果选择状态并单击“获取全部”,则为我提供该状态中的所有标记

这是代码“

$scope.markers=[];
var infoWindow=new google.maps.infoWindow();
var createMarker=函数(信息){
$scope.selectedbenches=info;
var marker=new google.maps.marker({
map:$scope.map,
职位:新google.maps.LatLng(info.lat,info.lng),
优化:错,
标题:信息城,
图标:“assets/img/marker.png”
});
$scope.allSelectedbenches=函数(){
控制台.log($scope.selectedbenches);
};
$scope.myCartItems=[];
$scope.addToCart=函数(项)
{
$http.get(serviceBase+'control/board/'+项)
.成功(功能(项目)
{
$scope.myCartItems.push(项目);
});
$scope.input='';
setItem('todos',JSON.stringify($scope.myCartItems));
};
$scope.remove=函数(索引){
$scope.myCartItems.splice(索引1);
};
google.maps.event.addListener(标记,'click',(函数(标记,$scope){
返回函数(){
var compiled=$compile(marker.content)($scope);
$scope.$apply();
infoWindow.setContent(已编译[0]);
infoWindow.open($scope.map,marker);
};
})(范围)
);
$scope.markers.push(marker);
marker.content=“”
+
''
+
''
+
'序列号:'
+
''
+
info.serial\n
+
''
+
''
+ ''
+
'说明:'
+
''
+
信息描述
+
''
+
''
+
''
+
“上次报告:”
+
''
+
info.last_报告
+
''
+
''
+
''
+
'已创建:'
+
''
+
info.created_在
+
'' + ''
+
''
+
''
+
''
+
''
+
''
+
“”+“”+info.city\u name+“”+“”+marker.content;
}
对于(i=0;i0){
对于(i=0;i0){
对于(i=0;i $scope.markers = [];
        var infoWindow = new google.maps.InfoWindow();


        var createMarker = function (info) {
            $scope.selectedbenches = info;
            var marker = new google.maps.Marker({
                map: $scope.map,
                position: new google.maps.LatLng(info.lat, info.lng),
                optimized: false,
                title: info.city,
                icon: 'assets/img/marker.png'

            });

            $scope.allSelectedbenches = function () {
                console.log($scope.selectedbenches);
        };
 $scope.myCartItems = [];

            $scope.addToCart = function (item)
            {
                $http.get(serviceBase + 'control/board/' + item)
                        .success(function (item)
                        {
                            $scope.myCartItems.push(item);

                        });
                $scope.input = '';
                localStorage.setItem('todos', JSON.stringify($scope.myCartItems));
            };

            $scope.remove = function (index) {
                $scope.myCartItems.splice(index, 1);
            };
            google.maps.event.addListener(marker, 'click', (function (marker, $scope) {
                return function () {
                    var compiled = $compile(marker.content)($scope);
                    $scope.$apply();
                    infoWindow.setContent(compiled[0]);
                    infoWindow.open($scope.map, marker);
                };
            })(marker, $scope)
                    );
            $scope.markers.push(marker);
            marker.content = '<div class="iw-container" style="color: #000;">'
                    +
                    '<div class="iw-content">'
                    +
                    '<b>'
                    +
                    'Serial number: '
                    +
                    '</b>'
                    +
                    info.serial_n
                    +
                    '</div>'
                    +
                    '<div class="iw-content">'
                    + '<b>'
                    +
                    'Description: '
                    +
                    '</b>'
                    +
                    info.desc
                    +
                    '<b>'
                    +
                    '</div>'
                    +
                    '<div class="iw-content">'
                    +
                    'Last report: '
                    +
                    '</b>'
                    +
                    info.last_report
                    +
                    '<b>'
                    +
                    '</div>'
                    +
                    '<div class="iw-content">'
                    +
                    'Created: '
                    +
                    '</b>'
                    +
                    info.created_at
                    +
                    '</div>' + '<input type="button" value="Add bench" ng-model="input" ng-click="addToCart(' + info.id + ')"/>'
                    +
                    '<div class="iw-content">'
                    +
                    '<img border="0" float="left" src="https://pbs.twimg.com/profile_images/691936998156804096/iveb6l4U.png">'
                    +
                    '<img border="0" float="right" src="http://www.fibrexgroup.com/images/Products/SSB001-main.jpg">'
                    +
                    '</div>'
                    +
                    '</div>'
                    +
                    '<div class="iw-title" style="color: #000;">' + '<h2>' + info.city_name + '</h2>' + '</div>' + marker.content;

        }

        for (i = 0; i < lokacije.length; i++) {
            createMarker(lokacije[i]);
        }

        $scope.openInfoWindow = function (e, selectedMarker) {
            e.preventDefault();
            google.maps.event.trigger(selectedMarker, 'click');
        }




        $scope.clearMarkers = function () {
            for (var i = 0; i < $scope.markers.length; i++) {
                $scope.markers[i].setMap(null);
            }
            $scope.markers.length = 0;
        }


 //Country filter
        $scope.filterMarkersCountry = function () {
            //1.select filtered country
            var filteredCountries;
            var selectedCountry = $scope.country;
            if (selectedCountry == '0') {
                filteredCountries = lokacije;
            } else {
                filteredCountries = lokacije.filter(function (c) {
                    if (c.country_id == selectedCountry.id)
                        return c;
                });
            }
            //2.update markers on map
            $scope.clearMarkers();
            if (filteredCountries.length > 0) {
                for (i = 0; i < filteredCountries.length; i++) {
                    createMarker(filteredCountries[i]);
                }
            }
        };
 //State filter
        $scope.filterMarkersState = function () {
            //1.select filtered cities
            var filteredStates;
            var selectedStates = $scope.state;
            if (selectedStates == '0') {
                filteredStates = lokacije;
            } else {
                filteredStates = lokacije.filter(function (c) {
                    if (c.state_id == selectedStates.id)
                        return c;
                });
            }
            //2.update markers on map
            $scope.clearMarkers();
            if (filteredStates.length > 0) {
                for (i = 0; i < filteredStates.length; i++) {
                    createMarker(filteredStates[i]);
                }
            }
        };
        //City filter
        $scope.filterMarkersCity = function () {
            //1.select filtered cities
            var filteredCities;
            var selectedCities = $scope.city;
            if (selectedCities == '0') {
                filteredCities = lokacije;
            } else {
                filteredCities = lokacije.filter(function (c) {
                    if (c.city_id == selectedCities.id)
                        return c;
                });
            }
            //2.update markers on map
            $scope.clearMarkers();
            if (filteredCities.length > 0) {
                for (i = 0; i < filteredCities.length; i++) {
                    createMarker(filteredCities[i]);
                }
            }
        };

    });
<div class="narudzbe_lokacija">
                    <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
                        <h5>Odabir lokacije</h5>
                        <div>
                            <label class="control-label col-lg-12 col-md-12 col-sm-12 col-xs-12">Country: </label>
                            <select id="country" class="form-control" ng-model="country" ng-options="country as country.name for country in countries track by country.id" ng-change="getState(); filterMarkersCountry()">
                                <option value='country_id'>{{country.name}}</option>
                            </select>
                        </div>
                        <div>
                            <label class="control-label col-lg-12 col-md-12 col-sm-12 col-xs-12">States</label>
                            <select id="state" class="form-control" ng-disabled="!country" ng-model="state" ng-options="state as state.name for state in states track by state.id" ng-change="getCity(); filterMarkersState()">
                                <option value='state_id'>{{state.name}}</option>
                            </select>
                        </div>
                        <div>
                            <label class="control-label col-lg-12 col-md-12 col-sm-12 col-xs-12">City</label>
                            <select id="city" class="form-control" ng-disabled="!state" ng-model="city" ng-options="city as city.name for city in cities track by city.id" ng-change="filterMarkersCity()">
                                <option value='city_id'>{{city.name}}</option></select>        
                        </div>
                        <button ng-click="allSelectedbenches()">Get all</button>

                        <br />
                        <br />
                    </div> 
$scope.myCartItems = [];
            $scope.allSelectedbenches = function () {

                if($scope.filteredCities !== undefined){
                    $scope.myCartItems = $scope.filteredCities;
                }
                if($scope.filteredStates !== undefined){
                   $scope.myCartItems = $scope.filteredStates;

                }
                if($scope.filteredCountries !== undefined){
                    $scope.myCartItems = $scope.filteredCountries;

                } 
        };