dongre6227 2015-02-19 10:44
浏览 22
已采纳

由于以下原因,地理编码不成功零结果 - PHP变量

I am trying to display the address which is called from my sql database, I can't display the address I keep getting this error "Geocode was not successful for the following reason Zero_Results"

I tried to add the full address in one variable $address rather than using three variable $address , $county , $county but still not working and I cannot figure it out.

I would like to display the address as marker as you can see in the image.

Whenever I added new address into my db I would get new marker added into the map.

enter image description here

Any help,

Thanks in advance.

Here is the code I am working with :

$result = mysqli_query($con,"SELECT * FROM `test`") or die ("Error:      
 ".mysqli_error($con));
     while ($row = mysqli_fetch_array($result))
     {
            $address = $row['address'];
            $county = $row['County'];
            $country = $row['Country'];
     }
        mysqli_close($con); 

        <!DOCTYPE html>
         <html>
          <head>

       <script type="text/javascript"
           src="https://maps.googleapis.com/maps/api/js?                       
           key=mykey&sensor=false">

        </script>


         <script type="text/javascript">
          var geocoder;
          var map;
          function initialize() {
            geocoder = new google.maps.Geocoder();
            var latlng = new google.maps.LatLng(          
            53.41291,-8.243889999999965);
            var address = '<?php echo $address.', '.$country.', '.$county; ?                 
          >';

            var myOptions = {
              zoom: 6,
              center: latlng,
              mapTypeId: google.maps.MapTypeId.ROADMAP
            }
            map = new google.maps.Map(document.getElementById("map_canvas"),                  
             myOptions);
            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);
              }
            });
          }
        </script>
        </head>
        <body onload="initialize()">
          <div id="map_canvas" style="width:500px; height:500px"></div>

        </body>
        </html>
  • 写回答

1条回答 默认 最新

  • duande3134 2015-02-19 15:43
    关注

    My problem solved and my solution is :

                <script type="text/javascript">
                var geocoder;
                var map;
                function initialize(address) {
                geocoder = new google.maps.Geocoder();
                var latlng = new google.maps.LatLng(   
                  53.41291,-8.243889999999965);
    
    
                var myOptions = {
                  zoom: 6,
                  center: latlng,
                  mapTypeId: google.maps.MapTypeId.ROADMAP
                }
                map = new google.maps.Map(document.getElementById("map_canvas"),            
                myOptions);
                <?php
                require('connection.php');
    
                  $result = mysqli_query($con,"SELECT * FROM `test`") or die  
                    ("Error: ".mysqli_error($con));
                  $count = 0;
    
    
                ?>
                <?php  //Starts while loop so all addresses for the given 
                    // information will be populated.
                 $addresscounting=0;
                   while($row = mysqli_fetch_assoc($result)) //instantiates 
                     // array
               { ?>   
    
    
                 var address = "<?php echo $address ?>";
    
    
                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);
                  }
                });
    
             <?php
                   $count++;
    
                  } //ends while
              ?>
              }
    
              </script
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持