Is it possible in the line that begins with $sql = to use the variables that were defined earlier in javascript?
var southWestLat = map.getBounds().getSouthWest().lat();
var southWestLng = map.getBounds().getSouthWest().lng();
var northEastLat = map.getBounds().getNorthEast().lat();
var northEastLng = map.getBounds().getNorthEast().lng();
var coordinatesMap =
<?php
global $wpdb;
$sql = "SELECT user_id, lat, lng FROM coordinates WHERE lat>southWestLat and lat<northEastLat and lng>southWestLng and lng<northEastLng";
$rows = $wpdb->get_results($sql, OBJECT_K);
...
?>;
Since javascript is a client side language if is not possible to directly use them. You can however use AJAX to transfer values of those JS variables to the server. Execute your sql statement and return back the results in some JSON object for example.
HTH 🙂
Oki so say we have the following in JS
Now we want to send myvar to the server via AJAX. Here is how.
The url must be some script that will handle the ajax request. What will be echoed by that script will end up in the msg variable of the success callback.
AJAX Handler
To do this you will need to send an extra parameter with each AJAX request. If you look at the above example I added the action parameter. This will allow us to identify which action should be executed by the AJAX Hander.
ajaxhandler.php