简体   繁体   English

Gmap3 Google Maps使用地理编码的位置将地图居中

[英]Gmap3 Google Maps using a geocoded location to center the map

I am using Gmap3 http://gmap3.net/ to calculate customer location from stockists of products. 我正在使用Gmap3 http://gmap3.net/从产品库存商那里计算客户位置。 I can pull the addresses of the suppliers off the mysql db ok using php, but im not sure how to go about using the geocoded address in the first part to center the map on that location. 我可以使用php将供应商的地址从mysql db ok中拉出,但是我不确定如何使用第一部分中的地理编码地址将地图定位在该位置上。

The geocoded marker appears on the map just fine, but im not sure how to centre the map onto it. 经过地理编码的标记会很好地显示在地图上,但不确定如何将地图居中。

What I tried is center:latLng, but that doesnt seem to work. 我试过的是center:latLng,但这似乎不起作用。

    <script type="text/javascript">

      $(function(){

        $('#test1').gmap3({
            getlatlng:{
    address:  "Paris, France",
    callback: function(results){
      if ( !results ) return;
      $(this).gmap3({
        marker:{
          latLng:results[0].geometry.location,
                 }
      });
    }
  },
          map:{
            options:{
              center:[52.9045147,-2.1685132],
              zoom: 6
            }
          },
          marker:{
            values:[
                <?php
    include '../connect.php';
$sql = <<<SQL
SELECT * FROM `suppliers`
SQL;
if(!$result = $db->query($sql)){ die('There was an error running the query [' . $db->error . ']');}
while($row = $result->fetch_assoc()){
echo '{address:"'.$row['address'].'", data:"'.$row['name'].'"},';
    }
    ?>

            //  {address:"66000 Perpignan, France", data:"Perpignan ! <br> GO USAP !", options:{icon: "http://maps.google.com/mapfiles/marker_green.png"}}
            ],
            options:{
              draggable: false
            },
            events:{
              mouseover: function(marker, event, context){
                var map = $(this).gmap3("get"),
                  infowindow = $(this).gmap3({get:{name:"infowindow"}});
                if (infowindow){
                  infowindow.open(map, marker);
                  infowindow.setContent(context.data);
                } else {
                  $(this).gmap3({
                    infowindow:{
                      anchor:marker, 
                      options:{content: context.data}
                    }
                  });
                }
              },
              mouseout: function(){
                var infowindow = $(this).gmap3({get:{name:"infowindow"}});
                if (infowindow){
                  infowindow.close();
                }
              }
            }
          }
        });
      });
    </script>

This appears to work : 这似乎起作用:

          $(function(){

            $('#test1').gmap3({
                            getlatlng:{
        address:  "Paris, France",
        callback: function(results){
          if ( !results ) return;
          $(this).gmap3({
               map:{
                options:{
                  center:results[0].geometry.location,
                  zoom: 6
                }
              },
                     marker:{
              latLng:results[0].geometry.location,  
                     }
          });
        }
      },

              marker:{
                values:[
                    <?php
        include '../connect.php';
    $sql = <<<SQL
    SELECT * FROM `suppliers`
    SQL;
    if(!$result = $db->query($sql)){ die('There was an error running the query [' . $db->error . ']');}
    while($row = $result->fetch_assoc()){
    echo '{address:"'.$row['address'].'", data:"'.$row['name'].'"},';
        }
        ?>

                //  {address:"66000 Perpignan, France", data:"Perpignan ! <br> GO USAP !", options:{icon: "http://maps.google.com/mapfiles/marker_green.png"}}
                ],
                options:{
                  draggable: false
                },
                events:{
                  mouseover: function(marker, event, context){
                    var map = $(this).gmap3("get"),
                      infowindow = $(this).gmap3({get:{name:"infowindow"}});
                    if (infowindow){
                      infowindow.open(map, marker);
                      infowindow.setContent(context.data);
                    } else {
                      $(this).gmap3({
                        infowindow:{
                          anchor:marker, 
                          options:{content: context.data}
                        }
                      });
                    }
                  },
                  mouseout: function(){
                    var infowindow = $(this).gmap3({get:{name:"infowindow"}});
                    if (infowindow){
                      infowindow.close();
                    }
                  }
                }
              }
            });
          });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM