<td><!--지도부분 -->
<div id="mgmap"></div>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&language=ko®ion=kr&key=AIzaSyBZJaZ4yjdbM6020UjVP78zno0PDplE-ng"></script> <script type="text/javascript">
var map;
var geocoder;
var marker;
var ymakerimg = '<?php echo $board_skin_url ?>/img/mapicon001.png';
function mgminfomap(){
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng('<?=$write[wr_3]?>','<?=$write[wr_4]?>'); //초기화면부분
var mgmapOption = {
zoom : 16,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById('mgmap'), mgmapOption);
marker = new google.maps.Marker({
position:latlng,
icon : ymakerimg,
map:map
});
// 이동시 좌표와 주소 변경이벤트
google.maps.event.addListener(map, 'dragend', function(){
moveLatlng();
changeAddress();
});
};
// 이동시 좌표구하기
function moveLatlng(){
var mll=map.getCenter();
document.getElementById('wr_3').value = mll.lat();
document.getElementById('wr_4').value = mll.lng();
addMark(mll.lat(), mll.lng());
}
function changeAddress(){
geocoder.geocode( { 'location': map.getCenter()}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var str="";
for(var i=3; i>=0; i--){
str += " "+results[0].address_components[i].short_name;
}
document.getElementById('wr_1').value=str;
document.getElementById('wr_2').value=str;
}
});
}
function codeAddress(){
var address = document.getElementById('wr_1').value;
// 주소입력안했을때 경고창
if(address=='검색할 주소를 입력하십시오.' || address==''){
alert('검색할 주소를 입력하십시오.');
document.getElementById("wr_1").value='';
document.getElementById("wr_1").focus();
return;
}
geocoder.geocode({'address':address}, function(results, status){
if(status == google.maps.GeocoderStatus.OK){
map.setCenter(results[0].geometry.location);
addMark(results[0].geometry.location.lat(), results[0].geometry.location.lng());
document.getElementById('wr_2').value = results[0].formatted_address;
document.getElementById('wr_3').value = results[0].geometry.location.lat();
document.getElementById('wr_4').value = results[0].geometry.location.lng();
}
});
}
function addMark(lat,lng){
if(typeof marker!='undefined'){
marker.setMap(null);
}
marker = new google.maps.Marker({
map: map,
icon : ymakerimg,
position: new google.maps.LatLng(lat,lng)
});
var infowindow = new google.maps.InfoWindow({
});
}
function moveMarker(lat, lng){
marker.setPosition(lat, lng);
}
function mypoint(){
// 나의위치 찾아보기
if (navigator.geolocation) {
browserSupportFlag = true;
navigator.geolocation.getCurrentPosition(function(position){
var initialLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
// 좌표를 주소로변환
geocoder.geocode({'latLng' : initialLocation}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
document.getElementById('wr_2').value = results[3].formatted_address;
document.getElementById('wr_1').value = results[3].formatted_address;
}
}
});
document.getElementById('wr_3').value = position.coords.latitude;
document.getElementById('wr_4').value = position.coords.longitude;
map.setCenter(initialLocation);
marker.setPosition(initialLocation);
}, function(){
handleNoGeolocation(browserSupportFlag);
});
}
else if (google.gears) {
browserSupportFlag = true;
var geo = google.gears.factory.create('beta.geolocation');
geo.getCurrentPosition(function(position){
var initialLocation = new google.maps.LatLng(position.latitude, position.longitude);
// 좌표를 주소로변환
geocoder.geocode({'latLng' : initialLocation}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
document.getElementById('wr_2').value = results[3].formatted_address;
document.getElementById('wr_1').value = results[3].formatted_address;
}
}
});