Google Map API Version3 教程(四):给marker标记加上自定义内容
2012-07-20 15:31
302 查看
转自:http://blog.sina.com.cn/s/blog_4cdc44df0100u9g1.html
Google Map API Version3 中标记可以给marker加上任何自己的东西。
效果如下:
代码:
首先还是定义一个marker:
lat = 23.14746;
lng = 113.34175376;
var myLatLng = new google.maps.LatLng(lat, lng);
var myOptions = {
zoom: 15,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.TERRAIN
};
var map = new google.maps.Map(document.getElementByIdx_x_x_xx_x("map_canvas"), myOptions);
var marker = new google.maps.Marker({
position: myLatLng,
title: "Hello World!"
});
marker.setMap(map);
然后给marker标记添加点击事件和自定义内容:
var contentString = '<div id="content">' +
'<div>' +
'</div>' +
'<h1>我的标签</h1>' +
'<div id="bodyContent">' +
'<p class = "mapStyle">我的淘宝 <a href="http://ggydggyd.taobao.com">http://ggydggyd.taobao.com</a>' +
'</div>' +
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
google.maps.event.addListener(marker, 'click', function () {
infowindow.open(map, marker);
});
infowindow是google指定的现实内容的类,你用HTML代码初始化它就好了
mapStyle是自己定义的样式,在这里可以使用网页的css样式表
示例代码下载:http://download.csdn.net/source/3331139
Google Map API Version3 中标记可以给marker加上任何自己的东西。
效果如下:
代码:
首先还是定义一个marker:
lat = 23.14746;
lng = 113.34175376;
var myLatLng = new google.maps.LatLng(lat, lng);
var myOptions = {
zoom: 15,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.TERRAIN
};
var map = new google.maps.Map(document.getElementByIdx_x_x_xx_x("map_canvas"), myOptions);
var marker = new google.maps.Marker({
position: myLatLng,
title: "Hello World!"
});
marker.setMap(map);
然后给marker标记添加点击事件和自定义内容:
var contentString = '<div id="content">' +
'<div>' +
'</div>' +
'<h1>我的标签</h1>' +
'<div id="bodyContent">' +
'<p class = "mapStyle">我的淘宝 <a href="http://ggydggyd.taobao.com">http://ggydggyd.taobao.com</a>' +
'</div>' +
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
google.maps.event.addListener(marker, 'click', function () {
infowindow.open(map, marker);
});
infowindow是google指定的现实内容的类,你用HTML代码初始化它就好了
mapStyle是自己定义的样式,在这里可以使用网页的css样式表
示例代码下载:http://download.csdn.net/source/3331139
相关文章推荐
- 百度地图Api进阶教程-用户自定义数据(标记和搜索)7.html
- 高德地图 搜索以后 多个marker绑定点击事件 自定义窗口内容
- Discuz!教程之新手站长如何自定义导航内容
- EasyAR尝鲜系列教程之自定义Marker的实现
- [导入] 转[教程] 学习如何使用有趣的自定义标记来布局页面!
- 百度地图Api进阶教程-用户自定义数据(标记和搜索)7.html
- Google Map API Version3 教程(三):代码添加和删除marker标记
- 百度地图4.1_1开发教程(8)为marker加上备注
- SVG.js Marker标记和自定义标签
- Win7系统如何自定义“开始”菜单内容?DIY“开始”菜单图文教程
- contentprovider 自定义内容提供者
- 读取app.config文件中的自定义内容
- Android初级教程之内容提供者获取联系人信息
- SonarQube插件开发自定义规则(2)常用api-扫描java文本内容
- 根据label的内容返回自定义cell的高度
- 发送邮件完成实例(张孝祥视频教程内容)
- PyCharm 教程(六)自定义文件模板
- Dialog如何实现显示自定义内容
- Scott Mitchell 的ASP.NET 2.0数据教程之十一: 基于数据的自定义格式化
- notepad++快速在每行头尾都加上指定的内容