Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Google Maps API中数据库中的多个地址_Php_Database_Google Maps Api 3 - Fatal编程技术网

Php Google Maps API中数据库中的多个地址

Php Google Maps API中数据库中的多个地址,php,database,google-maps-api-3,Php,Database,Google Maps Api 3,我在一个数据库中有一堆地址,我正试图找出如何在地图中放置多个地址。但地址取决于用户搜索的内容,如城市或卧室数量,因此地址总是根据用户搜索的内容而变化。到目前为止,我已经设法在地图上有了一个地址。我有没有办法将两者结合起来,以便在地图上显示您搜索到的地址及其点,或者修改我已有的代码 以下是谷歌地图api代码 var geocoder; var map; function initialize() {

我在一个数据库中有一堆地址,我正试图找出如何在地图中放置多个地址。但地址取决于用户搜索的内容,如城市或卧室数量,因此地址总是根据用户搜索的内容而变化。到目前为止,我已经设法在地图上有了一个地址。我有没有办法将两者结合起来,以便在地图上显示您搜索到的地址及其点,或者修改我已有的代码

以下是谷歌地图api代码

            var geocoder;
            var map;
            function initialize() {
              geocoder = new google.maps.Geocoder();
              var latlng = new google.maps.LatLng(49.2505, -123.1119);
              var mapOptions = {
                zoom: 15,
                center: latlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP
              }
              map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
            }

            function codeAddress() {
              var address = '<?php echo json_encode($varStreetAddress);?> <?php echo json_encode($varCity);?>, BC';
              geocoder.geocode( { 'address': address}, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                  map.setCenter(results[0].geometry.location);
                  var marker = new google.maps.Marker({
                      map: map,
                      position: results[0].geometry.location
                  });
                } else {
                  alert('Geocode was not successful for the following reason: ' + status);
                }
              });
            }

            google.maps.event.addDomListener(window, 'load', initialize);
var地理编码器;
var映射;
函数初始化(){
geocoder=新的google.maps.geocoder();
var latlng=新的google.maps.latlng(49.2505,-123.1119);
变量映射选项={
缩放:15,
中心:拉特林,
mapTypeId:google.maps.mapTypeId.ROADMAP
}
map=new google.maps.map(document.getElementById('map-canvas'),mapOptions);
}
函数代码地址(){
变量地址=',BC';
geocoder.geocode({'address':address},函数(结果,状态){
if(status==google.maps.GeocoderStatus.OK){
map.setCenter(结果[0].geometry.location);
var marker=new google.maps.marker({
地图:地图,
位置:结果[0]。几何体。位置
});
}否则{
警报('地理编码因以下原因未成功:'+状态);
}
});
}
google.maps.event.addDomListener(窗口“加载”,初始化);
下面是从数据库中搜索的代码

<?php
    $mysqli = new mysqli("localhost","root","", "");
        if ($mysqli->connect_errno) {
            echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
        }
///////////set search variables
$property = $_POST['property'];
$bedroom = $_POST['BedroomNumber'];
$bathroom = $_POST['BathroomNumber'];
$priceMin = $_POST['PriceMin'];
$priceMax = $_POST['PriceMax'];
$termlease = $_POST['TermLease'];
//////////search
if(isset($_POST['utilities']) && is_array($_POST['utilities'])) {
    foreach($_POST['utilities'] as $check) {
             //echoes the value set in the HTML form for each checked checkbox.
                         //so, if I were to check 1, 3, and 5 it would echo value 1, value 3, value 5.
                         //in your case, it would echo whatever $row['Report ID'] is equivalent to.
    }
}


$sql = $mysqli->query("select * from propertyinfo where Property like '%$property%' and NumBed like '%$bedroom%' and NumBath like '%$bathroom%' and Price >= '$priceMin' and Price <= '$priceMax' and utilities like '%$check%' and TermLease like '%$termlease%'");


if($sql === FALSE) {
    die(mysql_error()); // TODO: better error handling

}

if($sql->num_rows){
    while ($row = $sql->fetch_array(MYSQLI_ASSOC)){
        echo '<div id="listing">
                    <div id="propertyImage"> 
                        <img src="uploadimages/'.$row['imageName1'].'" width="200" height="150" alt=""/> 
                    </div>

                    <div id="basicInfo">
                    <h2>$'.$row['Price'].'</h2>
                    <p style="font-size: 18px;"># '.$row['StreetAddress'].', '.$row['City'].', BC</p>
                    <p>'.$row['NumBed'].' Bedrooms | '.$row['NumBath'].' Bathrooms | '.$row['Property'].'</p>
                    <br>
                    <p><a href="output2.php?record_id='.$row['ID'].'" class="link2" target="_blank">View Full Details</a> | <a href="" class="link2">Get Directions</a>

                    </div>
                </div>';

    }
}
else
{
echo '<h2>0 Search Results</h2>';
}?>

如果能看到html的重要部分就好了。这是用户在数据库中添加列表的动态页面吗

我发现(在一个类似的项目中)的问题是,当您使用“and”时,用户似乎需要选中所有框(或选择选项等)。任何东西都不能单独存在,否则会创建错误的搜索。您确实可以从查询中获得结果,但结果可能不正确。 我发现人们使用jquery,收集复选框,并将其与数据库进行比较。 用户可以选中所有的框,但大多数情况下,框将保持未选中状态,这意味着该类别中的所有框都是好的,而不是没有。例如,他们不检查2个、3个或4个浴室。这就意味着就浴而言,所有的性能都很好

而不是

function codeAddress() {
   var address = '<?php echo json_encode($varStreetAddress);?> <?php echo json_encode($varCity);?>, BC';
   geocoder.geocode( ....
}
函数代码地址(){
变量地址=',BC';
地理编码员。地理编码(。。。。
}
尝试:

函数代码地址(地址){
地理编码员。地理编码(。。。。
}
function codeAddress(address) {
   geocoder.geocode( ....
}
<?php
   while ($row = $sql->fetch_array(MYSQLI_ASSOC)){
      ...
      print "codeAddress($jsonAddress);\n";
      ...