Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.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 对于api web服务上的许多请求,是否可以用另一种方法来实现?_Javascript_Google Maps_Google Api - Fatal编程技术网

Javascript 对于api web服务上的许多请求,是否可以用另一种方法来实现?

Javascript 对于api web服务上的许多请求,是否可以用另一种方法来实现?,javascript,google-maps,google-api,Javascript,Google Maps,Google Api,我正在用谷歌api做一个应用程序。仅仅玩了几个小时后,我就注意到我已经把地点搜索api设置到了最大 我希望能够搜索地址并将其添加到地图中。我做错了吗?或者为什么我已经创建了这么多请求? 有可能在别处找到地址吗 我知道很难说我是否做错了,但从请求的外观上看,我想您可能会说我的代码正在处理许多请求 这是我正在使用的代码: $scope.initiateMap = function () { $scope.map = new google.ma

我正在用谷歌api做一个应用程序。仅仅玩了几个小时后,我就注意到我已经把地点搜索api设置到了最大

我希望能够搜索地址并将其添加到地图中。我做错了吗?或者为什么我已经创建了这么多请求? 有可能在别处找到地址吗

我知道很难说我是否做错了,但从请求的外观上看,我想您可能会说我的代码正在处理许多请求

这是我正在使用的代码:

            $scope.initiateMap = function () {
                $scope.map = new google.maps.Map(document.getElementById('map'), {
                    zoom: 11
                });
                //var marker = new google.maps.Marker({
                //    position: uluru,
                //    map: map
                //});

                navigator.geolocation.getCurrentPosition(function (position) {
                    var initialLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
                    $scope.map.setCenter(initialLocation);
                }, function () {
                    console.log('user denied request for position');
                    });

                var input = document.getElementById('address-field');
                var searchBox = new google.maps.places.SearchBox(input);
                //map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);

                $scope.map.addListener('bounds_changed', function () {
                    searchBox.setBounds($scope.map.getBounds());
                });

                var markers = [];
                searchBox.addListener('places_changed', function () {
                    var places = searchBox.getPlaces();
                    //var address_autocomplete = new google.maps.places.Autocomplete(address_input, { types: ['address'] });
                    //if (places.length == 0) {
                    //    return;
                    //}

                    // Clear out the old markers.
                    markers.forEach(function (marker) {
                        marker.setMap(null);
                    });
                    markers = [];

                    // For each place, get the icon, name and location.
                    var bounds = new google.maps.LatLngBounds();
                    places.forEach(function (place) {
                        if (!place.geometry) {
                            console.log("Returned place contains no geometry");
                            return;
                        }
                        if (place.types[0] !== "street_address") {
                            alert("not a street address");
                            markers = [];
                            markers.forEach(function (marker) {
                                marker.setMap(null);
                            });
                            return;
                        }
                        $scope.apartment.Address.Longitude = place.geometry.location.lng();
                        $scope.apartment.Address.Latitude = place.geometry.location.lat();

                        $scope.apartment.Address.AddressName = place.formatted_address;
                        var icon = {
                            url: place.icon,
                            size: new google.maps.Size(71, 71),
                            origin: new google.maps.Point(0, 0),
                            anchor: new google.maps.Point(17, 34),
                            scaledSize: new google.maps.Size(25, 25)
                        };

                        // Create a marker for each place.
                        markers.push(new google.maps.Marker({
                            map: $scope.map,
                            icon: icon,
                            title: place.name,
                            position: place.geometry.location
                        }));

                        if (place.geometry.viewport) {
                            // Only geocodes have viewport.
                            bounds.union(place.geometry.viewport);
                        } else {
                            bounds.extend(place.geometry.location);
                        }
                    });
                    $scope.map.fitBounds(bounds);
                });
            }

正如谷歌指南中所说,通过在谷歌API控制台上启用计费功能,您可以免费增加请求限制,每24小时最多可增加150000个请求。这只是为了验证你的身份,所以你的卡不会被收取费用


查看更多信息。

在谷歌的开发者控制台中,您可以看到您提出了多少请求,显示代码问题中的图像来自该控制台。或者你想要另一张图片?也许你可以把它设置为150k请求,就像这样:这里你有一个备选方案的比较foursquare是比较好的!我正在努力。感觉1000个请求过得真快。但也许这就是它的工作原理。