Google API geocode - 주소로 위경도 검색 v3

Open API/Google|2016. 11. 21. 18:12
반응형



geocode - 주소를 통한 위경도 조회하기 입니다. 

  

Test Url : http://www.uhoon.co.kr/test/602.html




<!doctype html>
<html>
<head>
    <meta charset="utf-8" />
    <title>googlemap v3 geocoder</title>
    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
</head>
<script type="text/javascript">
<!--
    $(function() {
        $("#getBtn").on("click", function(){ 
            var geocoder = new google.maps.Geocoder(); 
            var address = $("#address").val();
            geocoder.geocode( { 'address': address}, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    //var latLng = results[0].geometry.location;   
                    var lat = results[0].geometry.location.lat();
                    var lng = results[0].geometry.location.lng();
                    $("#lat").html(lat);
                    $("#lng").html(lng);
                }
            });
        });
    });
//-->
</script>
<body> 
<div>
    <input type="text" id="address" /><input type="button" value="get Lat,Lng" id="getBtn" />
</div>
<div>
    lat : <span id="lat"></span>
</div>
<div>
    lng : <span id="lng"></span>
</div>
</body>
</html>


댓글()