0

データベースにたくさんの住所があり、マップに複数の住所を配置する方法を見つけようとしています。ただし、住所は都市や寝室の数など、ユーザーが検索するものに依存するため、検索するものに応じて常に変化します。これまでのところ、地図上に 1 つの住所を持つことができました。2つを組み合わせる方法はありますか?検索した住所を地図上のポイントとともに表示するか、既に持っているコードを変更しますか?

ここにGoogleマップの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);

これがデータベースから検索するコードです

<?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>';
}?>
4

2 に答える 2

0

それ以外の ...

function codeAddress() {
   var address = '<?php echo json_encode($varStreetAddress);?> <?php echo json_encode($varCity);?>, BC';
   geocoder.geocode( ....
}

試す:

function codeAddress(address) {
   geocoder.geocode( ....
}
<?php
   while ($row = $sql->fetch_array(MYSQLI_ASSOC)){
      ...
      print "codeAddress($jsonAddress);\n";
      ...

map.setCenter も codeAddress fn の外に移動する必要があることに注意してください。

于 2013-07-02T12:31:41.297 に答える