javascript – Google Map API V3 – 点击标记将显示更多信息内容作为重叠式广告(如在Google Maps中)

前端之家收集整理的这篇文章主要介绍了javascript – Google Map API V3 – 点击标记将显示更多信息内容作为重叠式广告(如在Google Maps中)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我们使用Google Map Api V3在 HTML容器中加载Google地图.我们有一个位置搜索表单.在提交时,我们将获取可用的位置并在地图中设置标记.加载标记后,点击每个标记,我们需要显示标题,地址详细信息和设计,就像我们在Google地图中所使用的那样. (在谷歌地图 – 当点击红色的标记,我们可以看到更多的信息重叠框与额外的细节,如星星,路线,附近搜索,保存到地图,更多..)

我们是否内置了api功能来加载如上所述的叠加框.或者我们没有加载细节的功能,就像我们目前在谷歌地图中一样.

当我在谷歌和地图文档中搜索时,我可以看到显示叠加窗口的选项,并在框内写入内容.但是我没有看到根据需要加载内容的选项.

我已经粘贴下面的代码以供参考.

  1. var map = null;
  2. gmap_ready = function (){
  3. var myLatlng = new google.maps.LatLng(43.834527,-103.564457);
  4. var myOptions = {
  5. zoom: 3,center: myLatlng,mapTypeId: google.maps.MapTypeId.ROADMAP
  6. }
  7. map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);

}

  1. function fnLoadMarkers(){
  2. var locations = [
  3. ['S Dakota',43.834527,-103.564457,1],['Texas',31.428663,-99.418947,2],['California',36.668419,-120.249025,3],['Newyork',43.197167,-76.743166,4],['Missouri',38.410558,-92.73926,5]
  4. ];
  5. setMarkers(map,locations);
  6. }
  7. function setMarkers(map,locations) {
  8. var image = 'images/marker.gif';
  9.  
  10. for (var i = 0; i < locations.length; i++) {
  11. var currLocation = locations[i];
  12. var latLng = new google.maps.LatLng(currLocation[1],currLocation[2]);
  13. var marker = new google.maps.Marker({
  14. position: latLng,map: map,icon: image,title: currLocation[0],zIndex: currLocation[3]
  15. });
  16. google.maps.event.addListener(marker,'click',function() {
  17. var latitude = this.position.lat();
  18. var longitude = this.position.lng();
  19. window.open("http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q="+latitude+","+longitude+"&sll="+latitude+","+longitude+"&sspn=0.172749,0.4422&ie=UTF8&ll="+latitude+","+longitude+"&spn=0.162818,0.4422&z=11&iwloc=A");
  20. });
  21. }

}

如果有任何提示如何实现这些结果,这将是有益的.此外,请指导,无论是通过Google API V3可能.

提前致谢,

问候

Srinivasan.C

解决方法

我不明白你为什么要从Google Maps API标记向Google Maps打开一个新窗口?
您无法通过网址在Google地图上添加信息窗口.

这就是我这样做.

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <Meta name="viewport" content="initial-scale=1.0,user-scalable=no" />
  5. <Meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
  6. <link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
  7. <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
  8. <script type="text/javascript">
  9. // Initiate map
  10. function initialize(data) {
  11. // Make position for center map
  12. var myLatLng = new google.maps.LatLng(data.lng,data.lat);
  13.  
  14. // Map options
  15. var myOptions = {
  16. zoom: 10,center: myLatLng,mapTypeId: google.maps.MapTypeId.HYBRID
  17. };
  18.  
  19. // Initiate map
  20. map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
  21.  
  22. // Info window element
  23. infowindow = new google.maps.InfoWindow();
  24.  
  25. // Set pin
  26. setPin(data);
  27. }
  28. // Show position
  29. function setPin(data) {
  30. var pinLatLng = new google.maps.LatLng(data.lng,data.lat);
  31. var pinMarker = new google.maps.Marker({
  32. position: pinLatLng,data: data
  33. });
  34.  
  35. // Listen for click event
  36. google.maps.event.addListener(pinMarker,function() {
  37. map.setCenter(new google.maps.LatLng(pinMarker.position.lat(),pinMarker.position.lng()));
  38. map.setZoom(18);
  39. onItemClick(event,pinMarker);
  40. });
  41. }
  42. // Info window trigger function
  43. function onItemClick(event,pin) {
  44. // Create content
  45. var contentString = pin.data.text + "<br /><br /><hr />Coordinate: " + pin.data.lng +"," + pin.data.lat;
  46.  
  47. // Replace our Info Window's content and position
  48. infowindow.setContent(contentString);
  49. infowindow.setPosition(pin.position);
  50. infowindow.open(map)
  51. }
  52. </script>
  53. </head>
  54. <body onload="initialize({lat:-3.19332,lng:55.952366,text:'<h2>Edinburgh</h2><i>Nice city!</i>'})">
  55. <div id="map_canvas">
  56. </div>
  57. </body>
  58. </html>

猜你在找的JavaScript相关文章