我使用map.html哪里是谷歌地图api与标记谁得到缩放标记(self.jqXHR = $ .post("script.php", JSON.stringify(data), this.onDataFetched);
),我有script.php哪里是来自mysql的查询谁我的标记
一切都很好但我想在map.html中实现html表单,谁可以更改sql查询脚本.php页面
有人可以帮我解决问题吗?我应该在表格中写下什么? 现在我有类似<form method="post" action="script.php" id="searchform">
的东西,但是它会转到script.php - 我能做什么?
我正在使用其中描述的代码:http://blog.loleksy.pl/2014/02/02/google-maps-handling-huge-amount-of-markers/
我在<body>
标记中添加了HTML文件格式:
<form method="post" action="script.php" id="searchform">
city <input type="text" name="city"><br>
<input type="submit" name="submit" value="filter"></form>
我很伤心 - 我的代码就像示例:
<?php
/* config */
$config = array(
'user' => 'someuser',
'password' => 'somepassword',
'dbName' => 'somedb',
'host' => 'localhost'
);
/* connection */
$pdo = new \PDO('mysql:host='.$config['host'].';dbname='.$config['dbName'],$config['user'], $config['password']);
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
/* request */
$data = @file_get_contents('php://input');
if(!$data){
exit;
}
$data = json_decode($data, true);
/* logic */
function getResults($db, $data, $maxResults = 500){
/* filter data */
if(!isset($data['southWest']['lat']) || !isset($data['northEast']['lat']) ||
!isset($data['southWest']['lng']) || !isset($data['northEast']['lng'])){
return array ('needZoom' => false, 'markers' => array());
}
$a = (float)$data['southWest']['lat'];
$b = (float)$data['southWest']['lng'];
$c = (float)$data['northEast']['lat'];
$d = (float)$data['northEast']['lng'];
$condition1 = $a < $c ? "lat BETWEEN $a AND $c":"lat BETWEEN $c AND $a";
$condition2 = $b < $d ? "lng BETWEEN $b AND $d":"lng BETWEEN $d AND $b";
/* get count */
$countQuery = "
SELECT COUNT(id) as count
FROM ex1_cities
WHERE
( $condition1 ) AND ( $condition2 )
";
$countStmt = $db->query($countQuery);
$countResult = $countStmt->fetch(\PDO::FETCH_ASSOC);
$count = (int)$countResult['count'];
/* need zoom */
if($count>$maxResults){
return array('needZoom' => true);
}
/* get markers */
$resultQuery = "
SELECT id, name, country_code, lat, lng
FROM ex1_cities
WHERE
( $condition1 ) AND ( $condition2 )
";
$resultStmt = $db->query($resultQuery);
$result = $resultStmt->fetchAll(\PDO::FETCH_ASSOC);
return array(
'needZoom' => false,
'markers' => $result
);
}
$output = getResults($pdo, $data);
/* response */
header('Content-Type: application/json');
echo json_encode($output);
使用html表单我希望修改此部分 - 根据表单数据
$resultQuery = "
SELECT id, name, country_code, lat, lng
FROM ex1_cities
WHERE
( $condition1 ) AND ( $condition2 )
";
谢谢!
答案 0 :(得分:0)
我不知道这是不是你的期望..?
这个代码只需发布您的input city
即可适应您的查询
你有什么期待?
谷歌地图上有很多像城市一样查询的标记吗? 请描述你的输出欲望!
$city = $_POST['city']
$resultQuery = "
SELECT id, name, country_code, lat, lng
FROM ex1_cities
WHERE
city = '$city'
";
答案 1 :(得分:0)
这是简单的一页,正如我在评论中提到的那样 请将此代码改为您的代码 在这个例子中,如果您输入万隆,它会将您的地图指向万隆 否则雅加达,默认为万隆
process
&#13;
将其保存为 .php
让我知道结果。
这条线是我提到的动作空
<?php
if (!empty($_POST['submit'])) {
$city = $_POST['searchcity'];
if (!empty($city)) {
//** This is your query should print if input is not empty **//
if ($city != "bandung") {
$printcity = "'Jakarta'";
$latlon = '-6.203, 106.8451';
}
}
else {
//** This is your query should print if input is empty **//
$printcity = "'Bandung'";
$latlon = '-6.9034494, 107.6431576';
}
}
else {
//** This is your query should print if not submit **//
$printcity = "'Bandung'";
$latlon = '-6.9034494, 107.6431576';
}
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Simple markers</title>
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
.search {
position: fixed;
border-radius: 2px;
float: left;
height: 30px;
line-height: 30px;
margin: 20px 0px 0px 80px;
padding-left: 10px;
width: 500px;
z-index: 50;
}
#searchsite {
padding: 0px 11px 0px 13px;
font-size: 15px;
border: 1px solid transparent;
border-radius: 2px 0px 0px 2px;
box-sizing: border-box;
height: 32px;
outline: medium none;
box-shadow: 0px 2px 6px rgba(0, 0, 0, 0.3);
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script>
function initialize() {
var myLatlng = new google.maps.LatLng(<?php echo $latlon ?>);
var mapOptions = {
zoom: 13,
center: myLatlng
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: <?php echo $printcity ?>
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div class="search">
<form action="" method="post">
<input type="text" id="searchcity" name="searchcity" size="45px" placeholder="site name(lowercse)">
<input type="submit" name="submit">
</form>
</div>
<div id="map-canvas"></div>
</body>
</html>
&#13;