Total number of markers in shortcode

New home Forums Visitor Generated Markers Total number of markers in shortcode

Tagged: 

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #70448
    nuances
    Participant

    Hi,

    Is there a way to show the total number of markers by use of a shortcode?

    That would really be awesome.

    Thanx!

    #70449
    Matthew
    Moderator

    Hi there,

    Thank you for getting back in touch with us, we do appreciate your time.

    Unfortunately, we do not have a shortcode that displays the number of markers on a map, however, this can be achieved using some custom JS code (Maps -> Settings -> Advanced Settings).

    With that said, the respective custom JS code that can be used is as follows:

    jQuery(function($){
       $(document).on('markersplaced.wpgmza', function(){
          const totalMarkers = WPGMZA.maps[0].markers.length;
          $('<h4 class="wpgmza_number_of_markers">Number of markers on the map: ' + totalMarkers + '</h4>').insertAfter('.wpgmza_map');
       }); 
    })

    The above custom JS code will display text below your map container showing how many markers are on the map.

    Please do let me know if this helps and answers your question?

    Kindest Regards,
    Matthew

    #70455
    nuances
    Participant

    Hi Matthew,

    Thanx for getting back to me this quick.

    As for the number of markers:
    I am happy to see that there is a possibility to show the number of markers.
    However, it would be so great to have a way (not specifically with shortcode, maybe via another way) to be able to show the number of markers in a span or something like that.
    The reason for this: we launched an event that went viral on national news resulting in many people placing markers as a sort of growing community. Therefore, if the number of markers continuesly increases (for instance showing on the homepage to create that community-feeling). We are also planning to show the number of markers on big screens in town to create even more awareness.
    So if there would be a way to show the number of markers outside the map, it would really be awesome!

    Another question:
    Is it possible to redirect a user to another URL once the marker is placed?

    Looking forward to your answer(s).

    Best regards, Maurice.

    #70473
    Matthew
    Moderator

    Hi Maurice,

    Thank you for your response and time on this, I really appreciate it!

    If you are wanting to retrieve the number of markers on the map externally, this functionality is not supported. However, you can display the number of markers on the map and then hide the map so that only the span is displayed.

    There are ways to get the number of markers on the map externally, however, this falls under customization work, which we currently do not have the capacity to take on at this stage.

    An idea of how this could be done is to get the number of records of markers in your database using SQL code. Alternatively, you could make use of the markers endpoint whereby you can use some code to get the number of markers in the endpoint. The marker REST endpoint would be: https://www.example.com/wp-json/wpgmza/v1/markers

    With regards to redirecting users to a different URL once they have submitted a marker, yes this is possible using the redirect_to VGM form shortcode parameter. More information on this can be seen here: https://www.wpgmaps.com/documentation/advanced-map-options/map-shortcode-parameters/#VGM_form

    I hope this answers your question?

    Kindest Regards,
    Matthew

    #70477
    nuances
    Participant

    Hi Matthew,

    Ok, thanx for your clear reply.
    The redirect works like a charm!

    And as for the number of markers: yeah, indeed I have given it a thought via hiding classes, etc. But I was hoping for a somewhat easier solution should it have excisted 😉

    Thanx!
    Cheers, Maurice.

    #70478
    Matthew
    Moderator

    Hi Maurice,

    That is fantastic news, I am happy to hear that it is working like a charm.

    Unfortunately we do not have an easier solution than hiding classes, however, we may look into this in the future.

    Should you require any further assistance, we are more than happy to help.

    Kindest regards,
    M

    #79080
    zen – faidzul
    Participant

    Hi Matthew, I am trying to get the marker count to be displayed on my map.

    Is it possible to show the count just according to current filtered markers on map?

    For example, my actual markers count in the database is around 25k. But when the user performs radius search, the count should only be based on the markers that are within the radius search.

    Thanks!

    #79099
    Matthew
    Moderator

    Hi @Zen,

    Thank you for getting in touch with us, we do appreciate your time.

    Yes this may be possible using some custom JS code, please see the below code:

    jQuery(function($){
      $(document).on('filteringcomplete.wpgmza', function(event){
        let map = event.map;
    
        let count = 0;
        for(let marker of map.markers){
          console
          if(typeof marker.user_location == 'undefined' && marker.googleFeature.visible){
            count++;
          }
        }
    
        // Use the 'count' where you want
      })
    })

    I hope this helps?

    Kindest Regards,
    Matthew

    #79123
    zen – faidzul
    Participant

    Hi Matthew.. Thanks for the code, it works great!

    Only some issues that I noticed.

    – Markers being clustered is not counted.
    – Seems like the marker that is showing current user’s location is also counted.

    Attached screenshot for your reference.

    I have disabled the cluster opt.
    With 21 pages of the marker list with 10 markers in each page, the count should be 206.

    Attachments:
    You must be logged in to view attached files.
    #79158
    Matthew
    Moderator

    Hi there,

    Thank you for your response and time on this, I really appreciate it!

    Please may I ask if you would be able to provide me with the link to your map so that I may run through the code and see what may be happening?

    I look forward to hearing back from you.

    Kindest regards,
    Matthew

    #79166
    zen – faidzul
    Participant
    This reply has been marked as private.
    #79182
    Matthew
    Moderator

    Hi Zen,

    Thank you for your response.

    I have attempted to view your site again, however, it appears that the following error occurs: Error establishing a database connection

    Please may you advise?

    Kindest Regards,
    Matthew

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.