过滤/搜索谷歌标记


filter/ search for google markers

i使用map.html哪里是谷歌地图API与标记谁获得缩放标记(self. html)。jqXHR = $。post("script.php", JSON.stringify(data), this.onDataFetched);),我有script.php哪里是从mysql谁得到我的标记查询

一切都很好,但我想在map.html中实现HTML表单,谁可以改变SQL查询脚本。php页面

有人能帮我解决吗?form statement应该怎么写?现在我有这样的<form method="post" action="script.php" id="searchform">,但然后它去脚本。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 )
        ";

谢谢!

我不知道这是否是你所期望的…?
下面的代码只是发布你的input city然后适应你的查询
你的期望是什么?

在谷歌地图上的地段标记有查询像城市?
请描述你的输出愿望!

$city = $_POST['city']
$resultQuery = "
            SELECT id, name, country_code, lat, lng 
            FROM ex1_cities 
            WHERE 
            city = '$city'
        ";

这是一个简单的页面,正如我在评论
中提到的请将此代码改编为您的代码
在这个例子中,如果你输入bandung,它会将你的映射指向bandung
否则雅加达,默认为万隆

<?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>

另存为任意.php
让我知道结果。
这一行是我提到的action empty

<form action="" method="post">