欢迎光临

木子屋

标题: 我要地图API常用方法

作者: dnawo

日期: 2011-04-29 10:48 PM

分类: Web编程

内容: 一、公共代码
复制内容到剪贴板 程序代码<div id="myMap" style="position:relative; width:700px; height:500px;"></div>
<script language="javascript" src="http://api.51ditu.com/js/maps.js "></script>
二、常用方法
1.获取点击处经纬度坐标
复制内容到剪贴板 程序代码<script language="javascript">
var maps = new LTMaps("myMap");
maps.cityNameAndZoom("fuzhou", 2);
maps.addControl(new LTStandMapControl());
LTEvent.addListener(maps, "click", function(position){
//说明：我要地图经纬度单位为NTU，和度的换算关系为 度 = NTU/100000

//方法一
var point = maps.getPointLatLng(position);
alert("点坐标：(" + point.getLongitude()/100000 + "," + point.getLatitude()/100000 + ")");

//方法二，getClickLatLng方法在范例中出现，类参考中无此方法
//http://api.51ditu.com/docs/mapsapi/examples/LTMaps/click_add_marker.htm
var point2 = maps.getClickLatLng(position);
alert("点坐标：(" + point2.getLongitude()/100000 + "," + point2.getLatitude()/100000 + ")");
} );
</script>
2.可视区域经纬度坐标范围
复制内容到剪贴板 程序代码<script language="javascript">
var maps = new LTMaps("myMap");
maps.cityNameAndZoom("fuzhou", 3);
maps.addControl(new LTStandMapControl());
LTEvent.addListener(maps, "click", function(position){
var bounds = maps.getBoundsLatLng();
alert("左上角:(" + bounds.getXmin()/100000 + "," + bounds.getYmax()/100000 + ") 右下角:(" + bounds.getYmin()/100000 + "," + bounds.getXmax()/100000 + ")");
});
</script>
3.鼠标移到标记显示标记信息
复制内容到剪贴板 程序代码<script language="javascript">
var maps = new LTMaps("myMap");
maps.centerAndZoom(new LTPoint(11930077,2610354), 3);
//标准缩放控件
maps.addControl(new LTStandMapControl());
//标注控件
var maker = new LTMarker(new LTPoint(11930077,2610354));
maps.addOverLay(maker);
LTEvent.addListener(maker,"mouseover", function(){
var win = this.openInfoWinHtml("个人博客。[<a href='http://www.mzwu.com/' target='_blank'>进入网站</a>]");
win.setTitle("木子屋");
win.closeInfoWindowWithMouse();
});
</script>

+ 查看当前日志评论 (0)

登录

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 1.070 ms

返回

标题: 我要地图API常用方法

你没有权限发表评论

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 1.070 ms

返回

暂无评论

返回

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 1.102 ms

返回