Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

265
Vistas
Leaflet will not display my marker, "TypeError: t is null"

I am trying to display a marker on my Leaflet map. This gives me the following error: TypeError: t is null

PHP code which uses Google Maps API to fetch co-ordinates:

<?php
if (isset($_POST["checkAddress"])) { //Checks if action value exists
    $checkAddress = $_POST["checkAddress"];
    $plus = str_replace(" ", "+", $checkAddress);
    $json = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address=' . $plus . '&key=KEY');
    $obj = json_decode($json);
    $mapLat = $obj->results[0]->geometry->location->lat;
    $mapLng = $obj->results[0]->geometry->location->lng;
    $coords = ('' . $mapLat . ', ' . $mapLng . '');
    echo $coords;
}
?>

jQuery which runs the PHP script and should display the co-ordinates on the Leaflet map:

$(document).ready(function() {
$("#button").click(function(){
    $.ajax({
        url: "geo.php",
        method: "POST",
        data: {
         checkAddress: $("#largetxt").val()
        },
        success: function(response){
         console.log(response);
         var marker = L.marker([response]).addTo(map);
        }
    });
});
});
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Oh, it's you again.

You are receiving a string as a response.

L.marker expects [lat, lng] but you are giving it ["lat, lng"] A string instead of two floats.

To fix this in JavaScript:

success: function(response){
    var coordinates = response.split(", "); //create an array containing lat and lng as strings
    coordinates[0] = parseFloat(coordinates[0]); //convert lat string to number
    coordinates[1] = parseFloat(coordinates[1]); //convert lng string to number
    var marker = L.marker(coordinates).addTo(map);
}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda