• 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

Smarty if isset

Transform array, set each array element with parent key php

Transpose and flatten multiple rows of array data [duplicate]

generate an Excel file using PHP

Install mysql client in docker image

PHP - Check if string contains words longer than 4 characters, then include "+ *", and for those shorter than 4 characters include only "*"

calling server using nusoap with complextype

PHP password_verify

Form repeater send wrong data with last element in Laravel

How to remove Deprecated SymfonyComponentDebugDebugClassLoader?

How to get an Array value inside an object in an array Php [duplicate]

Phalcon: setStatusCode returns empty response

Sum column values from multiple arrays

getting error while enter Command => php artisan route:list

PHP error: "The zip extension and unzip command are both missing, skipping."

About Contact Privacy policy Terms and conditions