我正在使用Gmap3 http://gmap3.net/从产品库存商那里计算客户位置。我可以使用php从mysql db ok中拉出供应商的地址,但是我不确定如何使用第一部分中的地理编码地址将地图定位在该位置。
经过地理编码的标记会很好地显示在地图上,但不确定如何将地图居中。
我试过的是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>
这似乎起作用:
$(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();
}
}
}
}
});
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句