See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

TurfJS + PHP + MySQL

General Tech Bugs & Fixes

Max. 2000 characters



( 5 months ago )

I have a PHP endpoint/service that receives Lat/Long data from a 3rd party. The data is then processed in PHP code and saved into a MySQL database. This process works fine without any issues.

I need to run some spatial queries against the data, like does the source point fall inside a polygon (polygon source is GeoJSON), what is the distance from the point to a line (line source is GeoJSON) and distance to the end of a line (following the line segments).

I found TurfJS can cover all these queries, BUT TurfJS is obviously client side JavaScript functions, so I'm unable to call the Turf functions from PHP, retrieve the output values to save it in MySQL.

Any suggestions?



( 5 months ago )

So I have gone the route of using Ajax/jQuery to post the JavaScript results to a PHP processing page.

In my page where I run the TurfJS functions, I added:

  <script src=''></script>
  <script src=""></script>

<div id="result"></div>

<script type="text/javascript">

   //--- Turf Functions ---

   //--- Post values to processing page ---

   $.post('savetodb.php', {postVal1:val1, postVal2:val2},



In my processing page (savetodb.php), I have:


$saveVal1 = $_POST['postVal1'];
$saveVal2 = $_POST['postVal2'];

echo 'Value1: '.$saveVal1.' Value2: '.$saveVal2;


Hope this post helps someone else some day!!


what's your interest