Google地图仅显示在美国的搜索结果

时间:2016-05-25 08:24:07

标签: javascript angularjs google-maps google-maps-api-3

我正在使用有角度的谷歌地图API。我的问题是当我的地理位置关闭时,我使用搜索框来搜索通用的,而不是地址限制的东西或商店,如" pizza"或者" ikea"该地图默认显示其在美国的结果。

我希望能够在关闭地理位置时选择我自己的默认位置。但我不知道该怎么做。

这是我的代码

  //SEARCH FEATURES

$scope.searchOpen = false;
$scope.searchModel = {}


//Add and remove css classes on search bar to show and hide the searchbar


$scope.toggleSearch = function () {

    $scope.searchModel.searchTerm = null;


    var searchFieldInput = document.getElementById('pac-input')

    if (searchFieldInput.classList.contains('searchactive')) {
        searchFieldInput.classList.remove('searchactive')
        searchFieldInput.classList.remove('pac-container')


    } else {
        searchFieldInput.classList.add('searchactive')
    }



}

$scope.$watch("searchModel.searchTerm", function (searchText) {
    $scope.filteredMarkers = $filter("filter")($scope.specialMarker, searchText);
    if (!$scope.filteredMarkers) {
        return;
    }
});


$scope.searchbox = {
    template: 'searchbox.tpl.html',
    position: 'top-left',
    options: {
        bounds: {}
    },
    events: {
        places_changed: function (searchBox) {
            $scope.repositionAllowed = false;

            places = searchBox.getPlaces()

            if (places.length == 0) {
                return;
            }
            // For each place, get the icon, place name, and location.
            newMarkers = [];
            var bounds = new google.maps.LatLngBounds();
            for (var i = 0, place; place = places[i]; i++) {

                // Create a marker for each place.
                console.log(place.place_id)
                 var marker = $scope.createMarker({
                    id: 's' + i,
                    title: place.name,
                                        address: place.formatted_address, 
                    lat: place.geometry.location.lat(),
                    lng: place.geometry.location.lng(),
                    place: place,
                    pointType: "search"
                })

                newMarkers.push(marker);

                bounds.extend(place.geometry.location);
            }

            $scope.map.bounds = {
                northeast: {
                    latitude: bounds.getNorthEast().lat(),
                    longitude: bounds.getNorthEast().lng()
                },
                southwest: {
                    latitude: bounds.getSouthWest().lat(),
                    longitude: bounds.getSouthWest().lng()
                }
            }

            $scope.map.zoom = 13;
            $scope.map.markers = newMarkers;

            document.getElementById("pac-input").blur();








        }
    }
}


        $scope.defaultBounds = new google.maps.LatLngBounds(
        new google.maps.LatLng(37.9839, 22.7294),
        new google.maps.LatLng(38.9839, 24.31715));


    $scope.map.bounds = {
        northeast: {
            latitude: $scope.defaultBounds.getNorthEast().lat(),
            longitude: $scope.defaultBounds.getNorthEast().lng()
        },
        southwest: {
            latitude: $scope.defaultBounds.getSouthWest().lat(),
            longitude: -$scope.defaultBounds.getSouthWest().lng()

        }
    }
    $scope.searchbox.options.bounds = new google.maps.LatLngBounds($scope.defaultBounds.getNorthEast(), $scope.defaultBounds.getSouthWest());
});

感谢

0 个答案:

没有答案