안규 공부방

Javascript & JQuery & CSS > Google Maps API + 주소를 이용한 위치정보 뽑기

등록일 : 2017-07-14 17:12 조회수 : 93,931

주소를 이용한 그글 맵 표시 방법과, 위도/경도를 뽑는 소스 입니다.



	var GreenIcon = new google.maps.MarkerImage(
		"http://ankyu.entersoft.kr/images/choiankyu.jpg",
		new google.maps.Size(60, 60),
		new google.maps.Point(0, 0),
		new google.maps.Point(6, 20));
	
	//주소로 지도표시
	function codeAddress() 
	{
		var address = "전라북도 고창군 공음면 구암리 450-4";
		geocoder = new google.maps.Geocoder();

		var latlng = new google.maps.LatLng(37.52,126.92);
		var myOptions = {zoom: 19,  center: latlng,    mapTypeId: google.maps.MapTypeId.ROADMAP  };
		var map = new google.maps.Map(document.getElementById("map"), myOptions);

		geocoder.geocode( { 'address': address}, function(results, status) {
			if (status == google.maps.GeocoderStatus.OK) {
				$("#setPosition").html(results[0].geometry.location.toString());
				map.setCenter(results[0].geometry.location);
				
				var marker = new google.maps.Marker({
					map: map, 
					icon: GreenIcon,
					info: '말풍선 입니다.',				// 말풍선 안에 들어갈 내용.
					title : address,
					position: results[0].geometry.location
				});
			} else {
				alert("Geocode was not successful for the following reason: " + status);
			}
		});
	}


	function codeAddr()
	{
		var address = "전라북도 고창군 공음면 구암리 450-4";
		geocoder1 = new google.maps.Geocoder();
	
		geocoder1.geocode( { 'address': address}, function(results, status) {
			if (status == google.maps.GeocoderStatus.OK) {
				t_location = results[0].geometry.location.toString();
				t_location = t_location.replace("(","");
				t_location = t_location.replace(")","");
				t_location = t_location.replace(" ","");
				t_location = t_location.split(",");

				t_latitude = t_location[0];		//위도	
				t_longitude= t_location[1];		//경도


				$("#setPosition").html("Latitude: " + t_latitude + ", Longitude: " +t_longitude);
			} else {
				alert("Geocode was not successful for the following reason: " + status);
			}
		});
	}

	
※ 혹시 도움이 되셨다면 댓글에 한마디 남겨주세요!
작성자   비밀번호
자동글 방지     (자동글 방지 기능입니다.)
내용   댓글달기 
이메일 문의 : cak0280@nate.com  
Copyright 2000 By ENTERSOFT.KR All Rights Reserved.