• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

how to hide previous markers when new markers added in google map javascript api

javascriptphphtml


PHP Snippet 1:

const THRESHOLD = 3 // up to 3 active markers
let list = [] // list of markers

const onAddMarker = marker => {

    // init marker
    let marker = new google.maps.Marker([...opts]) 

    // push marker to list
    list.push(marker)

    // check list length and remove oldest marker (if needed)
    if (list.length > THRESHOLD)
        list.shift().setMap(null)
    
}

Related Snippets

Laravel whole batch is cancelled if one Job fails

PHP 8.1: strftime() is deprecated

PHP SoapClient: set a namespace without prefix

Woocommerce Checkout - Add conditional field required if one field is filled

Transpose and flatten two-dimensional indexed array where rows may not be of equal length

Redis Command To Sort Keys

Adding one microsecond to Datetime object in PHP

How to get AJAX to post on second page?

Exception thrown during the rendering of a template("Parameter "id" for route "url" must match "[^/]++" ("" given) to generate a corresponding URL.")

Error when uploading certain .png files "Interlace handling should be turned on when using png_read_image"

Dropdown with current value from Mysql

Fatal error: Uncaught Error: Call to undefined method mysqli_stmt::fetch_assoc() [duplicate]

PHP returning an error message and false

possible options to create pdf file using html elements to generate invoice in php and codeigniter

Accessors (Getter) & Mutators (Setter) On a Pivot Table in Laravel

About Contact Privacy policy Terms and conditions