0
전체 주소가있는 현재 위치가 있으며 ID로 <span>
에 표시했습니다. 하지만이 주소를 input type text
에도 표시하고 싶습니다. 현재 코드는입력 유형 텍스트에서 google api로 현재 주소를 얻는 방법
<script type="text/javascript">
var positionlatitude;
var positionlongitude;
var address;
google.maps.event.addDomListener(window, 'load', function() {
var places = new google.maps.places.Autocomplete(document.getElementById('[email protected]'));
google.maps.event.addListener(places, 'place_changed', function() {
var place = places.getPlace();
address = place.formatted_address;
positionlatitude = place.geometry.location.lat();
positionlongitude = place.geometry.location.lng();
});
});
navigator.geolocation.getCurrentPosition(success);
function success(position) {
var GEOCODING = 'https://maps.googleapis.com/maps/api/geocode/json?latlng=' + position.coords.latitude + '%2C' + position.coords.longitude + '&language=en';
$.getJSON(GEOCODING).done(function (location) {
$('span[id^="address"]').html(location.results[0].formatted_address);
})
}
</script>
<label for="location">Your Location: </label><br />
<span id="address" class="input-form" ></span>
<input type="text" value="" name="address" id="geolocation"/>