• 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

PHP's array_map including keys

PHP: How to raise number to (tiny) fractional exponent?

Read users and passwords from a txt file

Laravel/docker-compose/redis - Class 'Redis' not found

Symfony 4: "Autowire: you should configure its value explicitly."

Send same name multiple checkbox values via ajax

How do I upload a laravel project on cPanel shared hosting?

Lumen - Postgresql setup - Composer

Composer Warning: openssl extension is missing. How to enable in WAMP

Uncaught TypeError: Cannot read property 'length' of null when retrieving tags from wp

How to fix " Uncaught TypeError: Argument 1 passed to JpGraphException::defaultHandler() " problem in php 7.1.3 and jpgraph 4.2.6?

How to get Laravel's CSRF Token from Another Website?

Install mysql client in docker image

enable Apache http Authorization header

Dropdown with current value from Mysql

About Contact Privacy policy Terms and conditions