google map api v3 的marker使用label的方法(markerwithlabel的使用)
来源:互联网 发布:java 如何建立socket 编辑:程序博客网 时间:2024/06/08 03:56
在google v3里面取消了marker的label方法,所以要自己定义叠加层来使用带文字标签的标注,但是自定义的话非常繁琐,故引用现成的markerwithlabel.js即可以实现对标注添加label。在使用过程中发生这么一个问题:marker标注的图标虽然显示出来了,但是都是集中在一个点(貌似是最后一个marker的位置)。问题的原因是markerwithlabel.js的1.8版本有bug,要使用V1.9以上,markerwithlabel.js网盘下载地址http://pan.baidu.com/s/1hq9UH4C。
下面是一个简单的例子,先看效果图
下面是代码,(注意添加markerwithlabel.js以及google api 的key: <script type="text/javascript" src="http://maps.google.com/maps/api/js?key=YOURKEY&sensor=false"></script>
<script type="text/javascript" src="markerwithlabel.js"></script>
):
<span style="font-size:10px;"><!DOCTYPE html "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>MarkerWithLabel Example</title> <style type="text/css"> .labels { color: red; background-color: white; font-family: "Lucida Grande", "Arial", sans-serif; font-size: 10px; font-weight: bold; text-align: center; width: 40px; border: 2px solid black; white-space: nowrap; } </style> <script type="text/javascript" src="http://maps.google.com/maps/api/js?key=YOURKEY&sensor=false"></script> <script type="text/javascript" src="markerwithlabel.js"></script> <script type="text/javascript"> function initMap() { var latLng = new google.maps.LatLng(49.47805, -123.84716); var homeLatLng = new google.maps.LatLng(49.47805, -123.84716); var map = new google.maps.Map(document.getElementById('map_canvas'), { zoom: 12, center: latLng, mapTypeId: google.maps.MapTypeId.ROADMAP }); var marker = new MarkerWithLabel({ position: homeLatLng, draggable: true, map: map, labelContent: "$425K", labelAnchor: new google.maps.Point(22, 0), labelClass: "labels", // the CSS class for the label labelStyle: {opacity: 0.75} }); var marker2 = new MarkerWithLabel({ position: new google.maps.LatLng(49.475, -123.84), draggable: true, map: map, labelContent: "$395K", labelAnchor: new google.maps.Point(22, 0), labelClass: "labels", // the CSS class for the label labelStyle: {opacity: 0.75} }); var iw = new google.maps.InfoWindow({ content: "Home For Sale" }); var iw2 = new google.maps.InfoWindow({ content: "Another Home For Sale" }); google.maps.event.addListener(marker, "click", function (e) { iw.open(map, marker); }); google.maps.event.addListener(marker2, "click", function (e) { iw2.open(map, marker2); }); }; </script></head><body onload="initMap()"><p>A basic example of markers with labels. Note that an information window appears whether youclick the marker portion or the label portion of the MarkerWithLabel. The two markers shown hereare both draggable so you can easily verify that markers and labels overlap as expected.</p> <div id="map_canvas" style="height: 60%; width: 100%"></div> <div id="log"></div></body></html></span>
0 0
- google map api v3 的marker使用label的方法(markerwithlabel的使用)
- google map api v3 中markerwithlabel.js更新的使用
- google map api v3 不带marker图标的标签(infobox.js)
- Google Map API的使用
- google maps javascript API v3 and markerWithLabel
- wordpress中Google Map V3 for IDN 插件的使用
- android google map api的具体使用
- Google Map Place API的初步使用
- Google Maps JavaScript API V3的使用(一)
- Google Maps JavaScript API V3的使用(二)
- Google Maps JavaScript API V3的使用(三)
- Google Maps JavaScript API V3的使用(四)
- Google Map API使用中出现的“google未定义”解决办法
- google map的使用
- Google Map API使用详解(十四)——使用Google Map提供的默认控件
- Google Map API使用详解(十六)——使用GMapOptions定制你的Google Map
- android 使用Google map api v3 不用申请key!
- 使用google map v3 api 开发地图服务
- 20140714 「初等数论 - 拓展欧几里得+同余模方程」POJ 2115 C Looooops
- Windows XP模式
- HDU 4300 Clairewd’s message
- 打印输入中单词长度的直方图(垂直方向的直方图)
- [Android]Java中System.loadLibrary() 的执行过程
- google map api v3 的marker使用label的方法(markerwithlabel的使用)
- 深入理解Java内存模型(六)——final
- linux mmap初解
- py 异常
- uiwebview如何修改网络html
- GTMBase64
- robotium(上)
- SZ斐波拉契数列
- 安卓ADB端口被占用/ADB无法使用解决办法