gpt4 book ai didi

javascript - lat 和 lng 未正确插入数据库中

转载 作者:行者123 更新时间:2023-11-30 01:09:15 27 4
gpt4 key购买 nike

我有起点和目的地点的纬度和经度,如下所示。

1->Start:23.03234692854866,72.45964050292969 End:23.02823945776033,72.52281188964844 2->Start:23.02823945776033,72.52281188964844 End:23.037402105360147,72.58907318115234 3->Start:23.037402105360147,72.58907318115234 End:23.036770218630025,72.6309585571289

这里,第一个的结束值是第二个的起始值(参见上值的粗体部分)。

问题是当我尝试插入它时,它没有按照我想要的方式插入。它是这样插入的:

enter image description here

意味着,这里发生了很多变化。比如先来的数据最后插入。
那么问题出在哪里呢?

JAVASCRIPT 代码:

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+"&nbsp;&nbsp;&nbsp;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);
}
?>

我知道已弃用的函数。

最佳答案

据我所知,你有一个数组溢出

   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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com