根据纬度和长谷歌地图重新绘制地图
我在下面的URL中通过以下脚本生成谷歌地图
http://apryll.co.in/maps/index.php
var locations = [
['', -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'), {
zoom: 10,
center: new google.maps.LatLng(-33.92, 151.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 = new google.maps.Size(105, 53);
flagIcon_shadow.anchor = new google.maps.Point(20, 52);
var boxText = document.createElement("div");
boxText.style.cssText = "border: 1px solid black; margin-top: 8px; padding: 5px; display:block; ";
var myOptions = {
content: boxText
,disableAutoPan: false
,maxWidth: 0
,pixelOffset: new google.maps.Size(-261, -268)
,zIndex: null
,boxStyle: {
background: "url('images/metro-plot-bg-1.png') no-repeat -286px -1361px"
,opacity: 1
,width: "393px"
,height: "233px"
}
,closeBoxMargin: "11px 32px 2px 2px"
,closeBoxURL: "images/close.png"
,infoBoxClearance: new google.maps.Size(1, 1)
,isHidden: false
,pane: "floatPane"
,enableEventPropagation: false
};
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]),
icon: flagIcon_front,
shadow: flagIcon_shadow,
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
//infowindow.setContent(locations[i][0]);
//infowindow.open(map, marker);
ib.setContent(locations[i][0]);
ib.open(map, marker);
}
})(marker, i));
var ib = new InfoBox(myOptions);
//ib.open(map, marker);
}
我在页面上选择了不同的位置。
http://apryll.co.in/maps/index.php
当我选择下拉菜单时,它会将不同位置的纬度和经度作为ajax调用的响应。
现在我想用新接收到的经纬度和长度在响应文本中重绘google地图
感谢Adavance
没有想法的PHP所以不能提供示例代码,但这是你可以做的 -
由于您正在从数据库中获取从combobox中进行选择的latlng,因此您还可以将此功能添加到该数据库中。
首先,您应该将标记放置代码移动到一个单独的函数中。 从数据库中提取的值应传递给数组。 让这个数组只在这个函数中声明。 然后这个数组可以用于标记的位置,因为每次在组合框中改变选择时都会执行该函数。
你可以在我的这个问题中看到一些Asp.net代码。 希望它可以帮助你。
Latlng = new google.maps.LatLng(some_lat,some_lon);
map.panTo(Latlng);
你也可以使用
map.setCenter(Latlng);
不同之处在于,如果原始的经度和纬度足够接近新的动画,则panTo会以很好的动画进行动画。
请查看此处的文档:https://developers.google.com/maps/documentation/javascript/reference
您将不得不使用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);
你也可以使用map.panToBounds(边界),如果你想要看中
然后在某个地方
链接地址: http://www.djcxy.com/p/81507.html