새소식

개발관련/Google API

GoogleMap 좌표 변환(주소 -> lat,lng 로 변환)

  • -
SMALL

#기본 좌표 초기화
<?
//기본 좌표 지정
$lat = "22.2627924";
$lng = "113.96554190000006";
$mappoint = $lat.','.$lng;
?>

스크립트
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
 

<script type="text/javascript">
//
// Google map Api
//
var gmap;
var markers = [];
var geocoder;
var centericon = [];

function initialize() {
    geocoder = new google.maps.Geocoder();
        var subgps;
        var latlng = new google.maps.LatLng(<?= $mappoint?>);
        var myOptions = {
                zoom: 16,
                center: latlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP
                };
        gmap = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
        //makeMarker(shopinfo);
        centericon = new google.maps.Marker({
                position: subgps,
                map: gmap,
                icon:'/target.png'
        });

        google.maps.event.addListener(gmap, 'mousemove', function(e) {
                subgps = gmap.getCenter();
                centericon.setPosition(subgps);
                //test code
                document.getElementById('lat').innerHTML = gmap.getCenter();
        });
}

function changeCenter(){
        var p = gmap.getCenter();
        self.location.href = "<?= $PHP_SELF?>?shopid=<?= $shopid?>&work=change&ll=" + p.lat() + ',' + p.lng();
}




function makeMarker(location) {
        var markerOptions = {map: gmap, position: new google.maps.LatLng(location.lat, location.lng)};
        var marker = new google.maps.Marker(markerOptions);
        markers.push(marker);
}

function codeAddress() {
        //
        // 실제 반영 주소 넣기
        //
        address = "여기에 실제 주소를 넣어주세요.";
        geocoder.geocode( { 'address': address}, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                        gmap.setCenter(results[0].geometry.location);
                        subgps = gmap.getCenter();
                        centericon.setPosition(subgps);
                        //test code
                        document.getElementById('lat').innerHTML = gmap.getCenter();
                } else {
                        alert("none address: " + status);
                }
        });
}

//
// Google Map Api End
//
</script>
<div id="map_canvas" style="width: 500px; height: 400px"></div>
<div id="lat"></div>
<div id="lng"></div>

















LIST
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.