我知道同一主题存在很多问题,但我不能让它们在我的代码中工作,因为我需要以不同的方式来实现它... 我有一个html表单在db中插入信息,代码是:
<form name="form1" action="insert.php" method="post">
<input id="street" name="street" type="textbox" placeholder="street" maxlength="20" />
<input id="number" name="number" type="textbox" placeholder="number" maxlength="5" />
<input id="name" name="name" type="textbox" placeholder="Name" maxlength="40" /></div>
<input type="submit" id="submit" name="submit" value="Send" ></input>
</form>
“insert.php”文件是:
<?php
@$link = mysqli_connect("127.0.0.1","User","Pass","DB");
if(!$link){
die ("Error n°".mysqli_connect_errno().": ".mysqli_connect_error());
}
$sql = "INSERT INTO markers (Street, Number, Name)
VALUES ('{$_POST['street']}','{$_POST['number']}','{$_POST['name']}')";
$rs = mysqli_query ($link, $sqql);
if (!$rs){
die('Error n°'.mysqli_errno($link).": ".mysqli_error($link));
}
?>
我通常使用简单的Javascript GeoCoder函数:
<script>
function codeAddress() {
var number = document.getElementById('number').value;
var address = document.getElementById('street').value + ' ' + number + city;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
lat = results[0].geometry.location.lat();
lng = results[0].geometry.location.lng();
} else {
alert('Error: ' + status);
}
});
}
</script>
问题是我无法找到在表单中使用地理编码器在数据库中存储“lat”和“lng”变量的正确方法。并且,无论如何,如果我可以存储它们然后我无法进行更新,因为我只是可以更改地址而不是lat和lng数字来重新定位标记... 以下是创建标记的函数的代码:
<script>
var dblat = [];
var dblong = [];
var dbstreet = [];
var dbnumber = [];
var dbcont = 0;
<?php while ($v = mysqli_fetch_array($rs, MYSQL_ASSOC)) {
$latitude = $v['Latitude'];
$longitude = $v['Longitude'];
$street = $v['street'];
$number = $v['number'];
echo "dblatitude.push($latitud);";
echo "dblongitude.push($longitud);";
echo "dbstreet.push(\"$street\");";
echo "dbnumber.push($number);";
echo "dbcont = dbcont + 1;";
echo "dblatitud.length = dbcont;";
};
?>
function loadMarkers() {
for (var i = 0; i < dblatitud.length; i++) {
var latlong = new google.maps.LatLng(dblatitude[i], dblongitude[i]);
var marker = new google.maps.Marker({
map: map,
position: latlong,
animation: google.maps.Animation.DROP
});
}
}
</script>
我如何插入,如果需要,可以更新数据库中的lat和lng?
提前致谢