高德地图根据经纬度转换成地址JS代码demo
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>逆地理编码</title>
<link rel="stylesheet" type="text/css" href="http://developer.amap.com/Public/css/demo.Default.css" />
<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=d94035ac264f0cc5b293199360ca0e1e"></script>
<script language="javascript">
var mapObj;
function mapInit() {
mapObj = new AMap.Map("iCenter", {
view: new AMap.View2D({
center:new AMap.LngLat(121.428000,31.197600),//地图中心点
zoom:13 //地图显示的缩放级别
})
});
}
//已知点坐标
var lnglatXY = new AMap.LngLat(121.428000,31.197600);
function geocoder() {
var MGeocoder;
//加载地理编码插件
mapObj.plugin(["AMap.Geocoder"], function() {
MGeocoder = new AMap.Geocoder({
radius: 1000,
extensions: "all"
});
//返回地理编码结果
AMap.event.addListener(MGeocoder, "complete", geocoder_CallBack);
//逆地理编码
MGeocoder.getAddress(lnglatXY);
});
//加点
var marker = new AMap.Marker({
map:mapObj,
icon: new AMap.Icon({
image: "http://api.amap.com/Public/images/js/mark.png",
size:new AMap.Size(58,30),
imageOffset: new AMap.Pixel(-32, -0)
}),
position: lnglatXY,
offset: new AMap.Pixel(-5,-30)
});
mapObj.setFitView();
}
//鼠标划过显示相应点
var marker;
function onMouseOver (e) {
var coor = e.split(','),
lnglat = new AMap.LngLat(coor[0], coor[1]);
if (!marker) {
marker = new AMap.Marker({
map:mapObj,
icon: "http://webapi.amap.com/images/0.png",
position: lnglat,
offset: new AMap.Pixel(-10, -34)
});
} else {
marker.setPosition(lnglat);
}
mapObj.setFitView();
}
//回调函数
function geocoder_CallBack(data) {
var resultStr = "";
var roadinfo ="";
var poiinfo="";
var address;
//返回地址描述
address = data.regeocode.formattedAddress;
//返回周边道路信息
roadinfo +="<table style='width:600px'>";
for(var i=0;i<data.regeocode.roads.length;i++){
var color = (i % 2 === 0 ? '#fff' : '#eee');
roadinfo += "<tr style='background-color:" + color + "; margin:0; padding:0;'><td>道路:" + data.regeocode.roads[i].name + "</td><td>方向:" + data.regeocode.roads[i].direction + "</td><td>距离:" + data.regeocode.roads[i].distance + "米</td></tr>";
}
roadinfo +="</table>"
//返回周边兴趣点信息
poiinfo += "<table style='width:600px;cursor:pointer;'>";
for(var j=0;j<data.regeocode.pois.length;j++){
var color = j % 2 === 0 ? '#fff' : '#eee';
poiinfo += "<tr onmouseover='onMouseOver(\"" + data.regeocode.pois[j].location.toString() + "\")' style='background-color:" + color + "; margin:0; padding:0;'><td>兴趣点:" + data.regeocode.pois[j].name + "</td><td>类型:" + data.regeocode.pois[j].type + "</td><td>距离:" + data.regeocode.pois[j].distance + "米</td></tr>";
}
poiinfo += "</table>";
//返回结果拼接输出
resultStr = "<div style=\"font-size: 12px;padding:0px 0 4px 2px; border-bottom:1px solid #C1FFC1;\">"+"<b>地址</b>:"+ address + "<hr/><b>周边道路信息</b>:<br/>" + roadinfo + "<hr/><b>周边兴趣点信息</b>:<br/>" + poiinfo +"</div>";
document.getElementById("result").innerHTML = resultStr;
}
</script>
</head>
<body onload="mapInit();">
<div id="iCenter" ></div>
<div class="demo_box">
<input type="button" value="逆地理编码" onclick="geocoder()"/>
<div id="r_title"><b>查询结果:</b></div>
<div id="result"> </div>
</div>
</body>
</html>
高德地图根据经纬度转换成地址JS代码demo的更多相关文章
- 在微信小程序里自动获得当前手机所在的经纬度并转换成地址
效果:我在手机上打开微信小程序,自动显示出我当前所在的地理位置: 具体步骤: 1. 使用微信jssdk提供的getLocation API拿到经纬度: 2. 调用高德地图的api使用经纬度去换取地址的 ...
- 根据Unicode编码用C#语言把它转换成汉字的代码
rt 根据所具有的Unicode编码用C#语言把它转换成汉字的代码 var s = System.Web.HttpUtility.HtmlDecode(Utf8Str); var o = Newton ...
- Java将ip字符串转换成整数的代码
下面代码是关于Java将ip字符串转换成整数的代码,希望对各位有较大用途. public class IpUtil { public static int Ip2Int(String strIp){ ...
- js不同地图坐标系经纬度转换(天地图,高德地图,百度地图,腾讯地图)
1.js转换代码 1 //转换常数 2 var x_pi = 3.14159265358979324 * 3000.0 / 180.0; 3 var pi = 3.14159265358979324; ...
- js冒泡法和数组转换成字符串示例代码
将数组转换成字符串的方法有很多,讲解下js冒泡法的使用.js代码: //js冒泡法与数据转换为字符串的例子 //整理:www.jbxue.com window.onload = function(){ ...
- C# 13位时间戳转换成标准时间C#代码
原地址:https://www.cnblogs.com/yixuehan/p/5559244.html /// <summary> /// 时间戳转换成标准时间 /// </summ ...
- ASP.NET将word文档转换成pdf的代码
一.添加引用 using Microsoft.Office.Interop.Word; 二.转换方法 1.方法 C# 代码 /// <summary> /// 把Word文件转换成pdf文 ...
- 城市连动纯js代码DEMO
前台代码 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" co ...
- 【高德地图API】从头德国高中生JS API(三)覆盖物——大喊|折线|多边形|信息表|聚合marker|点蚀图|照片覆盖
覆盖物,是一张地图的灵魂.有覆盖物的地图.才是完整的地图.在一张地图上,除了底层的底图(瓦片图,矢量图),控件(有功能可操作的工具).最重要最必不可少的就是覆盖物了.覆盖物有多种.包含.标注.折线.多 ...
随机推荐
- ORA-00265: instance recovery required, cannot set ARCHIVELOG
OS: Oracle Linux Server release 5.7 DB: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - ...
- hdu 2066 一个人的旅行
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2066 一个人的旅行 Description 虽然草儿是个路痴(就是在杭电待了一年多,居然还会在校园里迷 ...
- hdu 1047 Integer Inquiry
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1047 Integer Inquiry Description One of the first use ...
- Java使用FileLock实现Java进程互斥锁
原理:JDK的nio包中FileLock实现类似Linux fcntl的文件锁, 可使文件被进程互斥访问. 借助此功能, 可以实现强大的Java进程互斥锁, 从而在应用层面保证同一时间只有惟一的Ja ...
- 代码编译方式 ant +ivy
Apache Ant,是一个将软件编译.测试.部署等步骤联系在一起加以自动化的一个工具,大多用于Java环境中的软件开发.由Apache软件基金会所提供. 没用过ant,了解一下,无非就这些功能, 编 ...
- linux 禁止指定账号ssh登陆
1 2 3 4 vim /etc/pam.d/sshd #在第一行添加以下代码 auth required pam_listfile.so item=user sense=de ...
- iOS另类的内存管理
iOS的内存管理算是老生常谈的问题了,我们写iOS的时候无时无刻不在涉及到内存管理.从开始的MRR(manual retain-release)到后来ARC(Automatic Reference C ...
- centos6.3编译安装Apache2.4.3+PHP5.4.8+Mysql5.5.8
以虚拟机VirtualBox 版本是4.1.20(内存设置为512M,centos安装是文本模式下安装),全新以最小化包安装了32位的 CentOS6.3系统,作为本地web环境,上次讲了在windo ...
- JAVA类与对象(五)----对象的生成、使用
对象的生成 创建一个对象包括对象的声明.实例化.初始化三部分. 1.声明-----类名对象名 声明并不是为对象分配内存空间,而只是分配一个引用空间.对象的引用类似于指针,是32位的地址空间,它的值指向 ...
- P3384: [Usaco2004 Nov]Apple Catching 接苹果
一道DP题, f[i,j,k] 表示 第 k 时刻 由 1 位置 变换 j 次 到达 当前 i 棵树 注意也要维护 变换 0 次的情况. var i,j,k,t,w,now:longint; tree ...