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

111
Views
Returning coordinate pairs with data via json

I have a script that submits parameters via JS $.ajax and on my PHP page I query db and return matched data.

echo json_encode(array("matches" => $match));

It works fine, but now I need to add coordinates date as lat/lon pairs. So I am able to get this via a loop but I'm not sure how to return it back to my script.

$crds = array();

foreach ($data as $row) {

    $lat = $row['lat'];
    $lon = $row['lon'];
    $key = $row['key'];

    $crds[$key] = $lat.'|'.$lon;
    ...
}

echo json_encode(array("coords" => $crds));

When the data comes back to my script I can see in response:

{"coords":["44.76315|-101.8113","41.76313|-111.8993","40.76299|-112.8994"]}

I wasn't sure how to format it so I joined it with a pipe which is probably a bad idea.Also in my script I need to loop through it to output an array that will look something like this:

markerArray.push(L.marker([44.76315,-101.8113]));
markerArray.push(L.marker([41.76313,-111.8993]));
markerArray.push(L.marker([40.76299,-112.8994])); 

Feel like I'm not making any progress and am making bad code choices... Need some help to untangle this. Thanks.

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

0

The data already looks like the correct structure, so just respond with it as-is:

echo json_encode(array("coords" => $data));

Then in js loop over it to add each one to markerArray (data being the ajax response).

data.coords.forEach((coord) => markerArray.push(L.marker([coord.lat,coord.lon]));

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!