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

362
Views
jQuery ajax GeoJson coordsToLatLngs devolución de datos - Objeto LatLng no válido: (indefinido, ...)

Así que estoy tratando de cambiar mis coordenadas para que mi polígono de fronteras de países en mi mapa no se estire verticalmente a lo largo de mi mapa.

Mis polígonos de borde aparecen pero incorrectamente. Así que implementé la función coordsToLatLngs de Leaflet y obtengo un objeto LatLng no válido: (undefined, -77.53466,23.75975,-77.78,23.71,-78.03405,24.28615,-78.40848,24.57564,-78.19087,25.2103,-77.57.5 ,24.34,-77.53466,23.75975)

¿No estás seguro de a qué podría estar apuntando el indefinido?

Gracias chicos.

Aquí está mi código

// agregar fronteras a los países

 $.ajax({ url: "libs/php/mapCountries.php", type: "POST", dataType: "json", success: function (result) { console.log(result); for (var i = 0; i < result.data.length; i++) { var latlng = L.GeoJSON.coordsToLatLngs(result.data[i].geometry.coordinates, 0, false); var polygon = L.polygon(result.data[i].geometry.coordinates, { color: "red" }).addTo(map); // zoom the map to the polygon map.fitBounds(polygon.getBounds()); } var coords = console.log(result); }, });

Aquí está mi JSON decodificado de mi archivo PHP

 { "data": [ { "type": "Feature", "properties": { "name": "Bahamas", "iso_a2": "BS", "iso_a3": "BHS", "iso_n3": "044" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [-77.53466, 23.75975], [-77.78, 23.71], [-78.03405, 24.28615], [-78.40848, 24.57564], [-78.19087, 25.2103], [-77.89, 25.17], [-77.54, 24.34], [-77.53466, 23.75975] ] ], [ [ [-77.82, 26.58], [-78.91, 26.42], [-78.98, 26.79], [-78.51, 26.87], [-77.85, 26.84], [-77.82, 26.58] ] ], [ [ [-77, 26.59], [-77.17255, 25.87918], [-77.35641, 26.00735], [-77.34, 26.53], [-77.78802, 26.92516], [-77.79, 27.04], [-77, 26.59] ] ] ] } } ] }
over 4 years ago · Santiago Trujillo
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!