Multiple Markers Google Map - showing max 50 locations, but I want to show 1000+

I have created an embedded google map in a htmlcomponent using the tutorial example (link below).
https://www.wix.com/velo/forum/coding-with-velo/example-multiple-markers-google-maps

The map is generally working well and is pulling in the locations, but only to a maximum of 50 locations - I have currently 1700 in the ‘Locations’ collection, and expect in time to have more (this is a fruit tree foraging map).
I can’t see why it is limiting it to the 50, other than that with the collections when you view them they often only display 50 until you scroll down - is it related?

Where/How can I change the limit so that all my locations will show in the map?

Website (Map) can be viewed at: https://www.fruitfool.co.nz/foraging-map

Let me know if there is a part of the coding or a screenshot you need to see.

Thanks,
Juanita

Seeing the code that gets info from Locations could be helpful, my first thought would be due to Limit or Include being used

@simen sorry, have been off sick. I can’t see any reference to Limit or Include but perhaps you can spot something that could be causing this? HTML Code & Velo Code also below.

HTML COMPONENT CODE:

Wix Code / Google Maps :: Multiple Markers
let foragerswhare = {lat: -43.500294, lng: 172.699520}; 

 /** 
   * The RestoreControl adds a control to the map that resets the zoom, 
   * and recenters the map on Barcelona. 
   * This constructor takes the control DIV as an argument. 
   * @constructor 
   */ 
   function RestoreControl(controlDiv, map) { 
        // Set CSS for the control border. 
        var controlUI = document.createElement('div'); 
        controlUI.style.backgroundColor = '#fff'; 
        controlUI.style.border = '2px solid #fff'; 
        controlUI.style.borderRadius = '3px'; 
        controlUI.style.boxShadow = '0 2px 6px rgba(0,0,0,.3)'; 
        controlUI.style.cursor = 'pointer'; 
        controlUI.style.marginBottom = '22px'; 
        controlUI.style.textAlign = 'center'; 
        controlUI.title = 'Click to reset the map'; 
        controlDiv.appendChild(controlUI); 

        // Set CSS for the control interior. 
        var controlText = document.createElement('div'); 
        controlText.style.color = 'rgb(25,25,25)'; 
        controlText.style.fontFamily = 'Helvetic Light,sans-serif'; 
        controlText.style.fontSize = '12px'; 
        controlText.style.lineHeight = '20px'; 
        controlText.style.paddingLeft = '5px'; 
        controlText.style.paddingRight = '5px'; 
        controlText.innerHTML = 'Restore Map'; 
        controlUI.appendChild(controlText); 

        // Setup the click event listeners: simply set the map to Chicago. 
        controlUI.addEventListener('click', function() { 
            map.setCenter(foragerswhare); 
            map.setZoom(15); 
        }); 
    } 

    let locations = null; 
    function init() { 
        if(locations === null) { // if no locations, let page know 
            window.parent.postMessage("hello", "*"); 
        } 
        window.onmessage = (event) => { 
            if (event.data) { 
                locations = event.data.markers; 
                let infowindow = new google.maps.InfoWindow(); 
                let map = new google.maps.Map(document.getElementById('map'), { 
                    zoom: 15, 
                    streetViewControl: false, 
                    center: foragerswhare   //{lat: -43.500294, lng: 172.699520}    // Foragers Whare is starting point 
                }); 

                // Add the markers to the map. 
                // Note: The code uses the JavaScript Array.prototype.map() method to 
                // create an array of markers based on a given "locations" array. 
                // The map() method here has nothing to do with the Google Maps API. 
var markers = locations.map(function (location) { 
                    let marker = new google.maps.Marker({ 
                        position: location.position, 
                        map: map 
                    }) 
                    google.maps.event.addListener(marker, 'mouseover', (function (marker) { 
                        return function () { 
                            infowindow.setContent(location.title); 
                            infowindow.open(map, marker); 
                        } 
                    })(marker)); 
                    google.maps.event.addListener(marker, 'mouseout', (function (marker) { 
                        return function () { 
                            infowindow.close(); 
                        } 
                    })(marker)); 
                    google.maps.event.addListener(marker, 'click', (function (marker) { 
                        window.parent.postMessage(location.title, "*"); 
                    })); 
                    return marker; 
                }); 

                // Add a marker clusterer to manage the markers. 
                var markerCluster = new MarkerClusterer(map, markers, 
                    { gridSize: 20, maxZoom: 16, imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m' }); 

                // Create the DIV to hold the control and call the CenterControl() 
                // constructor passing in this DIV. 
                var restoreControlDiv = document.createElement('div'); 
                var restoreControl = new RestoreControl(restoreControlDiv, map); 

                restoreControlDiv.index = 1; 
                map.controls[google.maps.ControlPosition.TOP_CENTER].push(restoreControlDiv);                         
            } 
        } 
    } 
</script> 
<script src="https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/markerclusterer.js"> 
</script>     
<script async defer src="https://maps.googleapis.com/maps/api/js?key=HAVEHIDDENMYAPIKEY=init"> 
</script> 

VELO PAGE CODE:

import { getLocations } from ‘backend/locations’ ;

$w . onReady ( function () {
sendLocations ();
$w ( “#html1” ). onMessage ( ( event ) => {
if ( event . data === ‘hello’ ) {
sendLocations ();
}
else {
$w ( ‘#text13’ ). text = "Fruit Type: " + event . data ;
}
} );
});

function sendLocations ( ) {
getLocations (). then (( locations ) => {
let markers = ;
for ( let i = 0 ; i < locations . length ; i ++) {
let loc = locations [ i ];
markers . push ({ title : loc . title , position : { lat : loc . latitude , lng : loc . longitude }});
}
$w ( ‘#html1’ ). postMessage ({ markers });
});
}

export function mobileButton1_click ( event ) {
$w ( “#columnStrip1” ). expand ();
$w ( “#mobileButton1” ). hide ();
$w ( “#mobileButton2” ). show ();
}

export function mobileButton2_click ( event ) {
$w ( “#columnStrip1” ). collapse ();
$w ( “#mobileButton1” ). show ();
$w ( “#mobileButton2” ). hide ();
}

The limit/include would be inside the query that’s probably in your getLocations function

This is the locations javascript that is loaded in the backend. I can’t find any documentation on what the export function getLocations() function does, but there is also no Limit or Include limitations in here. Thanks so much for your interest, any further ideas where I can hunt out this issue? Really appreciate the help.
import wixData from ‘wix-data’ ;
export function getLocations ( ) {
return wixData . query ( “Locations” )
. find ()
. then (( results ) => {
return results . items ; // items is an array of locations from the collection
})
. catch (( err ) => {
let errorMsg = err ;
});
}

@yisrael-wix this is built on your (amazing!) multiple markers tutorial (https://www.wix.com/velo/forum/tips-tutorials-examples/example-multiple-markers-google-maps), see above for more info, but I’m getting a limit of 50 markers showing on my map when I have plenty more loaded in my database. Any help would be very much appreciated.

wixData.query runs with a default limit of 50 which you can override.

I believe you are looking to add the following line after .find() and before .then

.limit(1000)

This link should help you - query - Velo API Reference - Wix.com

Hi Noah,

Thanks so much! I had suspected a default limit but didn’t know where to find that info - much appreciated.

So now I’m using the iterating query as suggested in the API docs but that is not working for me… it keeps erroring on the 'Cannot find name ‘wixData’. The API doc does not suggest to use import wixData from ‘wix-data’ ; and when I do try to do that it means the ‘retrieveAllItems’ greys out and no longer seems to work. Have tried it in various ways.

Any further ideas on what I need to do here? Really appreciate everyones help on this.

async function retrieveAllItems ( ) {
let results = await wixData . query ( “Locations” )
. limit ( 1000 )
. find ();
let allItems = results . items ;
while ( results . hasNext ()) {
results = await results . next ();
allItems = allItems . concat ( results . items );
}
return allItems ;
}