首页 > Windows开发 > 详细

腾讯地图api 地址解析 js版

时间:2018-10-04 06:26:00      阅读:277      评论:0      收藏:0      [点我收藏+]


<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">

<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta charset="utf-8" />
<script charset="utf-8" src="http://map.qq.com/api/js?v=2.exp"></script>
</head>
<body>
<input type="text" onblur="codeAddress(this.value)">
<input id = "lat" type = "text"><input id="lng" type="text" />
<script>
        var geocoder, map, marker = null;
   
        geocoder = new qq.maps.Geocoder();

        function codeAddress(address) {
            //var address = ‘中国,北京,海淀区,海淀大街38号‘;
            //对指定地址进行解析
            geocoder.getLocation(address);
            //设置服务请求成功的回调函数
            geocoder.setComplete(function(result) {
var arr = eval(result);

console.log(arr);
var location = arr.detail.location;

document.getElementById("lat").value=location.lat ;
document.getElementById("lng").value=location.lng;
            console.log(location);
            });
            //若服务请求失败,则运行以下函数
            geocoder.setError(function() {
                alert("出错了,请输入正确的地址!!!");
            });
        }
        codeAddress();
    </script>
</body>
</html>

腾讯地图api 地址解析 js版

原文:https://www.cnblogs.com/WangzLei/p/9740081.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!