title: Uncaught TypeError: Cannot read properties of null (reading 'lat') - Projection.SphericalMercator.js:19
body: <p>I am using leaflet to display a map and I wanted to place markers onto it. I wanted to place the markers using information I got from an API call from geoNames. However whenever I try to run the program it errors out with this message.
  <a href="https://i.stack.imgur.com/Z1yau.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Z1yau.png" alt="enter image description here" /></a>
  Projection.SphericalMercator.js:19</p>
  <pre><code>Uncaught TypeError: Cannot read properties of null (reading 'lat')
  at Object.project (Projection.SphericalMercator.js:19)
  at Object.latLngToPoint (CRS.js:7)
  at NewClass.project (Map.js:938)
  at NewClass.latLngToLayerPoint (Map.js:959)
  at NewClass.update (Marker.js:149)
  at NewClass.onAdd (Marker.js:65)
  at NewClass._layerAdd (Layer.js:60)
  at NewClass.whenReady (Map.js:1414)
  at NewClass.addLayer (Layer.js:119)
  at NewClass.addLayer (Layer.js:273)
  </code></pre>
  <p>I want to populate the map with markers based on information I retrieve and not have to hard code it.</p>
  
  <pre class="lang-js prettyprint-override"><code>//Get Nearby Wiki for Markers
  function nearbyPOIs(lat, lng) {
      $.ajax({
          url: 'libs/php/findNearbyWiki.php',
          type: 'POST',
          dataType: 'json',
          data: {
              lat: lat,
              lng: lng
          },
          //Successful Post Code AJAX call
          success: function(resultNearWiki) {
  
              if (resultNearWiki.status.name === &quot;ok&quot;) {
                  
                  //Create Marker
                  console.log(lat);
                  console.log(lng);
                  console.log(resultNearWiki);
                  console.log(JSON.stringify(resultNearWiki));
                  var nearWikiArray = resultNearWiki['data']['poi'];
                  console.log(nearWikiArray);
  
                  var nearWikiTypeClassArray = [];
                  var nearWikiTypeNameArray = [];
                  var nearWikiNameArray = [];
                  var nearWikiLatArray = [];
                  var nearWikiLngArray = [];
  
  
  
                  for (i = 0; i &lt; nearWikiArray.length; i++) {
                      nearWikiTypeClassArray.push(nearWikiArray[i]['typeClass']);
                      nearWikiTypeNameArray.push(nearWikiArray[i]['typeName']);
                      nearWikiNameArray.push(nearWikiArray[i]['name']);
                      nearWikiLatArray.push(nearWikiArray[i]['lat']);
                      nearWikiLngArray.push(nearWikiArray[i]['lng']);
                  }
  
                  console.log(nearWikiLatArray);
                  console.log(nearWikiTypeNameArray);
                  console.log(nearWikiNameArray);
                  
                  for (i = 0; i &lt; nearWikiArray.length; i++) {
                      createMarker(nearWikiLatArray[i], nearWikiLngArray[i], nearWikiNameArray[i], nearWikiTypeNameArray[i]);
                  } //When this commented out it works fine (doesn't plot still) but the rest of the code works as intended
  
                  markerLayerGroup.addTo(map);
                  
              }
          },
          //Error in Post Code Call
          error: function(jqXHR, textStatus, errorThrown) {
              console.log(lat);
              console.log(lng);
              console.log(textStatus + ' : ' + errorThrown);
              console.log(jqXHR);
          }
      });
  };
  </code></pre>
  <p>Get POIs
  &lt;?php</p>
  <pre><code>header(&quot;Access-Control-Allow-Origin: *&quot;);
  header(&quot;Access-Control-Allow-Headers: *&quot;);
  header(&quot;Access-Control-Allow-Methods: GET, POST, OPTIONS&quot;);
  header('Content-Type: application/json; charset=UTF-8');
  
  ini_set('display_errors', 'On');
  error_reporting(E_ALL);
  
  $executionStartTime = microtime(true);
  
  $url='http://api.geonames.org/findNearbyPOIsOSMJSON?lat=' . $_REQUEST['lat'] .'&amp;lng=' . $_REQUEST['lng'] . '&amp;maxRows=15&amp;radius=1&amp;username=username';
  
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_URL, $url);
  
  $result = curl_exec($ch);
  
  curl_close($ch);
  
  $decode = json_decode($result,true);
  
  $output['status']['code'] = &quot;200&quot;;
  $output['status']['name'] = &quot;ok&quot;;
  $output['status']['description'] = &quot;success&quot;;
  $output['status']['returnedIn'] = intval((microtime(true) - $executionStartTime) * 1000) . &quot; ms&quot;;
  $output['data'] = $decode;
  
  echo json_encode($output);
  </code></pre>
  <p>?&gt;</p>
  <p>I tried swapping out the for loop in the POIs call with a switch case and tried setting the data to global variables for which to call on later but neither work. When I type in the url with the data I want, it has the data I am trying to retrieve, the data is also printed to the console, it just won't let me access it. Thank you in advance.</p>