<!-- Google Map API -->
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBBXDjrF-o3CJNvUBa - pNCY5Bet_dhMVXg&callback=initMap" type="text/javascript"></script>
<!-- Code -->
<script type="text/javascript">
/** Google Map 객체. **/
GoogleMap = {
/* 초기화. */
initialize : function() {
this.input = document.getElementById("GoogleMap_input");
this.address = document.getElementById("GoogleMap_addr");
this.geocoder = new google.maps.Geocoder();
this.infowindow = new google.maps.InfoWindow();
//지도 생성.(기본 위치 서울.)
var latlng = new google.maps.LatLng(37.56641923090,126.9778741551);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
this.map = new google.maps.Map(
document.getElementById("GoogleMap_map"),myOptions);
//마커 생성.
this.marker = new google.maps.Marker({
map : this.map,
animation: google.maps.Animation.DROP
});
},
/* 주소 검색.(지오코딩) */
codeAddress : function() {
var address = this.input.value;
//콜백 함수 호출.
this.geocoder.geocode( { 'address': address},
function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
//검색 된 주소 목록.
GooglemMap.address.innerHTML = "";
var ul = document.createElement('ul');
for(var i=0; i<results.length; i++){
var li = document.createElement('li');
var a = document.createElement('a');
document.getElementById('map_1').value=results[0].geometry.location.lat(); // 좌표 값 저장
document.getElementById('map_2').value=results[0].geometry.location.lng(); // 좌표 값 저장
a.href = "#";
a.innerHTML = results[i].formatted_address;
GoogleMap.clickAddress(a, results[i].geometry.location,
results[i].formatted_address);
li.appendChild(a);
ul.appendChild(li);
}
GoogleMap.address.appendChild(ul);
}
});
},
//주소 클릭 이벤트.
clickAddress : function(a, addr,content){
a.onmousedown = function(){
//지도와 마커이동.
//alert(content);
document.getElementById('map_3').value=content; // 주소 저장
GoogleMap.map.setCenter(addr);
GoogleMap.marker.setPosition(addr);
GoogleMap.marker.setAnimation(google.maps.Animation.DROP);
GoogleMap.infowindow.setContent(content);
GoogleMap.infowindow.open(GoogleMap.map,GoogleMap.marker);
}
}
}
window.onload = function(){
GoogleMap.initialize();
}
</script>
위와 같이 되어 있는 소스를 다음지도로 변경하고자 합니다.
<script type="text/javascript" src="//dapi.kakao.com/v2/maps/sdk.js?appkey=xxx"></script>
<!-- Code -->
<script type="text/javascript">
/** Google Map 객체. **/
DaumMap = {
/* 초기화. */
initialize : function() {
this.input = document.getElementById("DaumMap_input");
this.address = document.getElementById("DaumMap_addr");
this.geocoder = new daum.maps.Geocoder();
this.infowindow = new daum.maps.InfoWindow();
//지도 생성.(기본 위치 서울.)
var latlng = new daum.maps.LatLng(37.56641923090,126.9778741551);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeId: daum.maps.MapTypeId.ROADMAP
};
this.map = new daum.maps.Map(
document.getElementById("DaumMap_map"),myOptions);
//마커 생성.
this.marker = new daum.maps.Marker({
map : this.map,
animation: daum.maps.Animation.DROP
});
},
/* 주소 검색.(지오코딩) */
codeAddress : function() {
var address = this.input.value;
//콜백 함수 호출.
this.geocoder.geocode( { 'address': address},
function(results, status) {
if (status == daum.maps.GeocoderStatus.OK) {
//검색 된 주소 목록.
DaumMap.address.innerHTML = "";
var ul = document.createElement('ul');
for(var i=0; i<results.length; i++){
var li = document.createElement('li');
var a = document.createElement('a');
document.getElementById('map_1').value=results[0].geometry.location.lat(); // 좌표 값 저장
document.getElementById('map_2').value=results[0].geometry.location.lng(); // 좌표 값 저장
a.href = "#";
a.innerHTML = results[i].formatted_address;
DaumMap.clickAddress(a, results[i].geometry.location,
results[i].formatted_address);
li.appendChild(a);
ul.appendChild(li);
}
DaumMap.address.appendChild(ul);
}
});
},
//주소 클릭 이벤트.
clickAddress : function(a, addr,content){
a.onmousedown = function(){
//지도와 마커이동.
//alert(content);
document.getElementById('map_3').value=content; // 주소 저장
DaumMap.map.setCenter(addr);
DaumMap.marker.setPosition(addr);
DaumMap.marker.setAnimation(daum.maps.Animation.DROP);
DaumMap.infowindow.setContent(content);
DaumMap.infowindow.open(DaumMap.map,DaumMap.marker);
}
}
}
window.onload = function(){
DaumMap.initialize();
}
</script>
그래서 위와 같이 변경했는데 적용이 안되서요…
확인 좀 부탁드릴께요…