Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
Plotting additional points on mapquest API map results in "Uncaught TypeError: t.addLayer is not a function"

I am trying to plot locations on a map using the Mapquest API. When the page is loaded, the first script generated the map, and places it in a div, which works properly.

When I call the function "plotPoint()" to add another point on the map, I get the following error: "Uncaught TypeError: t.addLayer is not a function"

<script src="https://api.mqcdn.com/sdk/mapquest-js/v1.3.2/mapquest.js"></script>

<script type="text/javascript">
    L.mapquest.key = 'KEY';
    var map;

      window.onload = function() {

        var map = L.mapquest.map('map', {
          center: [23.1596297, -82.2116596],
          layers: L.mapquest.tileLayer('map'),
          zoom: 8
        });

        L.marker([23.1596297, -82.2116596], {
          icon: L.mapquest.icons.marker(),
          draggable: false
        }).bindPopup('LOCATION 1').addTo(map);

        
      };

function plotPoint(){
        L.marker([23.1796297, -82.2416596], {
          icon: L.mapquest.icons.marker(),
          draggable: false
        }).bindPopup('LOCATION 2').addTo(map);
}
</script>

Any insight or suggestion would be most appreciated.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

map was declared as a local variable, when it should have been globally.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!