Google maps 基于lat和长google地图的地图重绘
我有一个谷歌地图生成由以下脚本在下面的网址 变量位置=[ ['', -33.890542, 151.274856, 4], ['', -33.923036, 151.259052, 5], ['', -34.028249, 151.157507, 3], ['', -33.80010128657071, 151.28747820854187, 2], ['', -33.950198, 151.259302, 1] ]; var map=new google.maps.map(document.getElementById('map'){ 缩放:10, 中心:新谷歌地图LatLng(-33.92151.25), mapTypeId:google.maps.mapTypeId.ROADMAP }); var flagIcon_front=new google.maps.MarkerImage(“images/marker.png”); var flagIcon_shadow=new google.maps.MarkerImage(“images/marker_shadow.png”) flagIcon_shadow.size=新的google.maps.size(105,53); flagIcon_shadow.anchor=新的google.maps.Point(20,52); var-boxText=document.createElement(“div”); boxText.style.cssText=“边框:1px纯黑色;页边距顶部:8px;填充:5px;显示:块;”; 变量myOptions={ 内容:boxText ,disableAutoPan:false ,最大宽度:0 ,pixelOffset:newGoogle.maps.Size(-261,-268) ,zIndex:null ,boxStyle:{ 背景:“url('images/metro-plot-bg-1.png')不重复-286px-1361px” ,不透明度:1 ,宽度:“393px” ,高度:“233px” } ,closeBoxMargin:“11px 32px 2px 2px” ,closeBoxURL:“images/close.png” ,infoBoxClearance:newgoogle.maps.Size(1,1) ,isHidden:错 ,窗格:“浮动窗格” ,enableEventPropagation:false }; var infowindow=new google.maps.infowindow(); var标记,i;Google maps 基于lat和长google地图的地图重绘,google-maps,google-maps-api-3,Google Maps,Google Maps Api 3,我有一个谷歌地图生成由以下脚本在下面的网址 变量位置=[ ['', -33.890542, 151.274856, 4], ['', -33.923036, 151.259052, 5], ['', -34.028249, 151.157507, 3], ['', -33.80010128657071, 151.28747820854187, 2], ['', -33.950198, 151.259302, 1] ]; var map=new google.maps.map(document.
对于(i=0;i不了解php,因此无法提供示例代码,但这是您可以做的- 当您在从组合框中进行选择时从数据库获取latlngs时,您还可以将此功能添加到组合框中 首先,您应该将标记放置代码移动到一个单独的函数中。从数据库中获取的值应该传递到一个数组。让此数组仅在此函数中声明。然后此数组可以用于放置标记,因为每次组合框中的选择更改时都会执行此函数
你可以在我的文章中看到一些Asp.net代码。希望它能帮助你。你必须使用google.maps.LatLngBounds()创建一个边界,然后用你的位置数组扩展它
bounds = new google.maps.LatLngBounds();
for(var count=0;count<locations.length;count++){
bounds.extend(new google.maps.LatLng(locations[count][1],locations[count[2]);
}
map.fitBounds(bounds);
bounds=new google.maps.LatLngBounds();
对于(变量计数=0;计数
你也可以使用
map.setCenter(Latlng);
不同之处在于,如果原始纬度和经度与新的纬度和经度足够接近,panTo将通过一个漂亮的动画来实现
请在此处查看文档:
为了解决上述问题,我做了以下几件事。希望能对您有所帮助
我已经创建了两个独立的
div with id="map" and id="map1".
<div id="map" style="width: 700px; height: 400px;"></div>
<div id="map1" style="width: 700px; height: 400px;"></div>
将新接收到的值传递到locations数组中。您尝试过吗?这就是我发现如何将其传递到数组的地方。页面没有刷新,我该如何做?在选择后,您从警报窗口中的何处获取这些latlng值?我通过向同一页面发送ajax请求从数据库获取这些值
map.setCenter(Latlng);
div with id="map" and id="map1".
<div id="map" style="width: 700px; height: 400px;"></div>
<div id="map1" style="width: 700px; height: 400px;"></div>
<script type="text/javascript">
window.onload = mapdata(38.8833,77.0167,<?php echo $jsonarray; ?>);
function mapdata(lat,lng,data){
var locations = data;
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 3,
center: new google.maps.LatLng(lat,lng),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
}
</script>
<script>
$(document).on("click",'#search',function(){
var zipcode=$("#zipcode").val();
if (zipcode!='') {
var market=$("#market").val();
var country=$("#country").val();
jQuery.ajax({ //passing value using the jquery
type:"POST",
data:"zipcode="+zipcode+"&market="+market+"&country="+country,
dataType:'json',
url: "<?php echo Yii::app()>createUrl('/front/front/mapsearch/')?>",
success: function(data){
if(data.detail != ''){
mapdata(data.lat,data.lng,data.detail);
}else{
$("#map").hide();
$("#map1").show();
$("#map1").html("Data Not Found...!!");
}
}
});
}
});
</script>
$result = array('lat'=>$lat,'lng'=>$lng,'detail'=>$marker);
$jsonarray = json_encode($result);
echo $jsonarray;