<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>