我有起点和终点的经纬度,如下所示。
1->开始:23.03234692854866,72.45964050292969结束:23.02823945776033,72.52281188964844
2->开始:23.02823945776033,72.52281188964844结束:23.037402105360147,72.58907318115234
3->开始:23.037402105360147,72.58907318115234结束:23.036770218630025,72.6309585571289
在此,第1个的结束值是第2个的开始值(请参见较高值的粗体部分)。
问题是当我尝试插入它时,它没有按我的意愿插入。它是这样插入的:
意思是,这里发生了很多变化,例如最后插入的数据先到先得。
那是什么问题呢?JAVASCRIPT CODE:
function save_waypoints()
{var ac;
var ad;
var k="1";
for (var m=0;m<tot_marker;m++)
{
ac +=k+"->Start:"+lat_arr[m].location+","+lon_arr[m].location+" End:"+lat_arr[m+1].location+","+lon_arr[m+1].location+","+k+"====<br>";
document.getElementById('e').innerHTML=ac;
var w=[],wp;
var rleg = directionsDisplay.directions.routes[0].legs[m];
/*data.start = {'lat': rleg.start_location.lat(), 'lng':rleg.start_location.lng()}
data.end = {'lat': rleg.end_location.lat(), 'lng':rleg.end_location.lng()}*/
data.start = {'lat': lat_arr[m].location, 'lng':lon_arr[m].location}
data.end = {'lat': lat_arr[m+1].location, 'lng':lon_arr[m+1].location}
var wp = rleg.via_waypoints
for(var i=0;i<wp.length;i++)w[i] = [wp[i].lat(),wp[i].lng()]
data.waypoints = w;
var str = JSON.stringify(data)
var jax = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
jax.open('POST','process.php');
jax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
jax.send('command=save&mapdata='+str)
jax.onreadystatechange = function(){ if(jax.readyState==4) {
if(jax.responseText.indexOf('bien')+1)alert('Updated');
else alert(jax.responseText)
}}
k++;
}
}
PHP
<? ob_start(); header('Cache-Control: no-store, no-cache, must-revalidate');
mysql_connect('localhost','cron','1234');
mysql_select_db('mapdir');
if($_REQUEST['command']=='save')
{
$data = $_REQUEST['mapdata'];
//$query = "update mapdir set value='$data'";
$query = "insert into `mapdir`(`value`) values('$data')";
if(mysql_query($query))die('bien');
die(mysql_error());
}
if($_REQUEST['command']=='fetch')
{
$query = "select value from mapdir";
/*if(!($res = mysql_query($query)))die(mysql_error());
$rs = mysql_fetch_array($res,1);
die($rs['value']);*/
$qry=mysql_query($query);
/*$rs = mysql_fetch_array($qry,1);
echo $rs['value'];*/
$ja = array();
while($rs = mysql_fetch_array($qry))
{
array_push($ja,$rs['value']);
}
echo json_encode($ja);
}
?>
I am aware of deprecated function.
最佳答案
从我看到的你有一个数组溢出
data.start = {'lat': lat_arr[m].location, 'lng':lon_arr[m].location}
data.end = {'lat': lat_arr[m+1].location, 'lng':lon_arr[m+1].location}
这会导致类似的问题...还是我错了?
关于javascript - lat和lng未正确插入数据库,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19565047/