如何使用Geocoder在带有计费帐户的Google地图中添加10多个标记?

时间:2018-10-16 10:59:32

标签: google-maps google-maps-markers google-geocoder

我有两种方法用于创建标记,另一种用于在地图上显示,我使用了地理编码器从地址中获取信息,但问题是我不能显示超过10个,有时不能显示9个,我有吗增加在Google控制台中的请求限制,或者代码有问题。我确定我已经启用了Google Maps javascript API和geocoder api,并且在浏览器中也没有任何错误

$scope.show_markers = function() {

    var latLng = {};
    latLng['latlng'] = {};

    angular.forEach($scope.locations, function(location, key) {
            var geocoder = new google.maps.Geocoder();
            geocoder.geocode({
                    'address': location.address
            }, function(results, status) {
                    if (status === 'OK') {
                            var lat = results[0].geometry.location.lat();
                            var lng = results[0].geometry.location.lng();
                            latLng['latlng']['lat'] = lat;
                            latLng['latlng']['lng'] = lng;

                            createMarker(lat, lng, location.address);
                    }
            });

    });
    return latLng;
};

function createMarker(lat, lng, location) {

    var storeWorkingHours = new Map();
    var store_marker_icon = {
            url: assets_root + "/img/store_marker.png",
            size: new google.maps.Size(100, 150),
            scaledSize: new google.maps.Size(50, 50),
            origin: new google.maps.Point(-10, -10)
    };
    var todayValue;
    $scope.link = null;


    for (var i = 0; i < $scope.locations.length; i++) {
            if ($scope.locations[i].address.trim() === location.trim()) {
                    storeWorkingHours.set($scope.locations[i].location_montag, $scope.locations[i].offnungszeiten_montag);
                    storeWorkingHours.set($scope.locations[i].location_dienstag, $scope.locations[i].offnungszeiten_dienstag);
                    storeWorkingHours.set($scope.locations[i].location_mittwoch, $scope.locations[i].offnungszeiten_mittwoch);
                    storeWorkingHours.set($scope.locations[i].location_donnerstag, $scope.locations[i].offnungszeiten_donnerstag);
                    storeWorkingHours.set($scope.locations[i].location_freitag, $scope.locations[i].offnungszeiten_freitag);
                    storeWorkingHours.set($scope.locations[i].location_samstag, $scope.locations[i].offnungszeiten_samstag);
                    storeWorkingHours.set($scope.locations[i].location_sonntag, $scope.locations[i].offnungszeiten_sonntag);
                    storeWorkingHours.set($scope.locations[i].location_heute, $scope.locations[i].offnungszeiten_heute);
                    storeWorkingHours.set("link", $scope.locations[i].hier_bewerben);
            }
    }

    var marker = new google.maps.Marker({
            map: $scope.map,
            position: new google.maps.LatLng(lat, lng),
            icon: store_marker_icon,
            content: storeWorkingHours,
            id: location,
            clickable: true,
            visible: true
    });
    var infoWindow = new google.maps.InfoWindow();
    marker.setMap($scope.map);
    $scope.allMarkers.push(marker);

    angular.forEach(storeWorkingHours, function(value, key) {
            if (key === getToday()) {
                    todayValue = value;
            }
    });
    marker.addListener('click', function() {
            closeAllInfoWindows($scope.infoWindows);
            stylingInfoWindow(infoWindow);
            $scope.infoWindows.push(infoWindow);
            var block_content = "<div class='marker_popup'>" +
                    "<div class='logo-popup'>AÏDA</div>" + "<div id='popUpAddress'>" + marker.id + "</div>" +
                    "<div class='working_hours'>" + heute_today + "   " + todayValue + "</div>" + "<div class='view_more'>" + mehr_erfahren_read_more + "<i class='fas fa-angle-right'></i></div>" + "</div>";
            infoWindow.setContent(block_content);
            infoWindow.open($scope.map, marker);
    });
    google.maps.event.addListener(infoWindow, 'domready', function() {
            // Reference to the DIV that wraps the bottom of infowindow
            var iwOuter = $('.gm-style-iw');
            $(iwOuter).click(function() {
                    $scope.viewMore(marker);
                    clearMarkers(marker);
                    infoWindow.close();
            });
    });
}

1 个答案:

答案 0 :(得分:0)

    for(int i =0;i<location.size();i++) {
        Latitude = Double.parseDouble(location.get(i).get("Latitude"));
        Longitude = Double.parseDouble(location.get(i).get("Longitude"));
        LatLng sydney = new LatLng(Latitude, Longitude);
        googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        if(i == 1)
            googleMap.addMarker(new MarkerOptions().position(sydney).title(location.get(i).get("LocationName")).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE)));
        else
            googleMap.addMarker(new MarkerOptions().position(sydney).title(location.get(i).get("LocationName")).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
        googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 15));

}