Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Younhj #22

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified nowhere/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified nowhere/__pycache__/settings.cpython-38.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion post/static/css/selectlocation.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ body {
/* 지도 외의 것 */
#lat, #lon {
font-size: 20px;
display: none;
/* display: none; */
}
#extrahead {
width: 100%;
Expand Down
66 changes: 42 additions & 24 deletions post/static/js/selectlocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,53 @@ navigator.geolocation.getCurrentPosition(function(position){
var mapContainer = document.getElementById('map'), // 지도를 표시할 div
mapOption = {
center: new kakao.maps.LatLng(position.coords.latitude, position.coords.longitude), // 지도의 중심좌표
level: 4 // 지도의 확대 레벨
level: 2 // 지도의 확대 레벨
};
var map = new kakao.maps.Map(mapContainer, mapOption); // 지도를 생성합니다

// 지도를 클릭한 위치에 표출할 마커입니다
var marker = new kakao.maps.Marker({
// 지도 중심좌표에 마커를 생성합니다
position: map.getCenter()
});
// 지도에 마커를 표시합니다
marker.setMap(map);

// 지도에 클릭 이벤트를 등록합니다
// 지도를 클릭하면 마지막 파라미터로 넘어온 함수를 호출합니다
kakao.maps.event.addListener(map, 'click', function(mouseEvent) {

// 클릭한 위도, 경도 정보를 가져옵니다
var latlng = mouseEvent.latLng;

// 마커 위치를 클릭한 위치로 옮깁니다
marker.setPosition(latlng);
// 지도를 생성합니다
var map = new kakao.maps.Map(mapContainer, mapOption);

document.getElementById("lat").value=latlng.getLat();
document.getElementById("lon").value=latlng.getLng();
// 주소-좌표 변환 객체를 생성합니다
var geocoder = new kakao.maps.services.Geocoder();

var message = '클릭한 위치의 위도는 ' + latlng.getLat() + ' 이고, ';
message += '경도는 ' + latlng.getLng() + ' 입니다';
var marker = new kakao.maps.Marker(), // 클릭한 위치를 표시할 마커입니다
infowindow = new kakao.maps.InfoWindow({zindex:1}); // 클릭한 위치에 대한 주소를 표시할 인포윈도우입니다

var resultDiv = document.getElementById('clickLatlng');
// 지도를 클릭했을 때 클릭 위치 좌표에 대한 주소정보를 표시하도록 이벤트를 등록합니다
kakao.maps.event.addListener(map, 'click', function(mouseEvent) {
searchDetailAddrFromCoords(mouseEvent.latLng, function(result, status) {
if (status === kakao.maps.services.Status.OK) {
var detailAddr = !!result[0].road_address ? '<div>도로명주소 : ' + result[0].road_address.address_name + '</div>' : '';

var content = '<div class="bAddr">' + detailAddr + '</div>';

var latlng = mouseEvent.latLng;
// 마커를 클릭한 위치에 표시합니다
marker.setPosition(mouseEvent.latLng);
marker.setMap(map);

document.getElementById("lat").value=latlng.getLat();
document.getElementById("lon").value=latlng.getLng();

// 인포윈도우에 클릭한 위치에 대한 법정동 상세 주소정보를 표시합니다
infowindow.setContent(content);
infowindow.open(map, marker);
}
});
});

// 중심 좌표나 확대 수준이 변경됐을 때 지도 중심 좌표에 대한 주소 정보를 표시하도록 이벤트를 등록합니다
kakao.maps.event.addListener(map, 'idle', function() {
searchAddrFromCoords(map.getCenter());
});

function searchAddrFromCoords(coords, callback) {
// 좌표로 행정동 주소 정보를 요청합니다
geocoder.coord2RegionCode(coords.getLng(), coords.getLat(), callback);
}

function searchDetailAddrFromCoords(coords, callback) {
// 좌표로 법정동 상세 주소 정보를 요청합니다
geocoder.coord2Address(coords.getLng(), coords.getLat(), callback);
}
})
19 changes: 12 additions & 7 deletions post/templates/selectlocation.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{%load static%}
<!DOCTYPE html>
<html lang="ko">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
Expand All @@ -10,31 +11,35 @@
<link rel="stylesheet" href="{% static 'css/selectlocation.css' %}">
<title>지금, 여기</title>
</head>

<body>
<div id="wrap">
{% include 'base.html' %}
<div id="extrahead">
<div id="post">
<form method="post">
<input type="text" id="lat" name="name" required minlength="4" maxlength="8" size="10">
<input type="text" id="lon" name="name" required minlength="4" maxlength="8" size="10">
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
<input type="text" id="lat" name="latitude">
<input type="text" id="lon" name="longitude">
<input type="text" id="address" name="concert_address">
<button type="submit" class="btn" id="button">등록</button>
</form>
</div>
<div id="extraheadbox">
<div id="info">
<p>마우스로 클릭해서 공연 위치를 표시해 주세요.</p>
</div>
<div id="uploadbtn">
<button class="btn" id="button">등록</button></form>
</div>
</div>
</div>
<div id="map">
<div id="realmap">
</div>
<script type="text/javascript" src="//dapi.kakao.com/v2/maps/sdk.js?appkey=48fb92eb759b013a41c30fdf66a85fc9"></script>
<script type="text/javascript"
src="//dapi.kakao.com/v2/maps/sdk.js?appkey=48fb92eb759b013a41c30fdf66a85fc9&libraries=services">
</script>
</div>
</div>
<script src="{% static 'js/selectlocation.js' %}"></script>
</body>

</html>
2 changes: 1 addition & 1 deletion post/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
urlpatterns = [
path('upload/', upload, name="upload"),
path('main/', main, name="main"),
path('selectlocation/', location, name="selectlocation"),
path('selectlocation/<int:Concert_id>/', location, name="selectlocation"),
path('update/<int:Concert_id>/', update, name="update"), # 수정됨
path('detail/<int:Concert_id>/', detail, name="detail"), #수정됨
path('delete/<int:Concert_id>/', delete, name="delete"), #수정됨
Expand Down
34 changes: 21 additions & 13 deletions post/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from .models import Concert
import json


# Create your views here.
def main (request):
concerts = Concert.objects.all()
Expand All @@ -22,22 +21,31 @@ def main (request):
concertJson = json.dumps(concertdict)
return render(request, 'main.html', {'concertJson':concertJson})

def location(request):
return render(request, 'selectlocation.html') # location => select
def location(request, Concert_id):
concert=Concert.objects.get(id=Concert_id)
if request.method == "POST":
concert.latitude = request.POST.get('latitude', None)
concert.longitude = request.POST.get('longitude', None)
concert.concert_address = request.POST.get('concert_address', None)
concert.save()
return redirect('/post/detail/' + str(concert.id)) # location => select
else:
return render(request, 'selectlocation.html') # location => select

def upload(request):
if request.method == "GET":
return render(request, 'upload.html')
elif request.method == "POST":
concert_title = request.POST.get('concert_title', None)
concert_player = request.POST.get('concert_player', None)
concert_location = request.POST.get('concert_location', None)
concert_detail = request.POST.get('concert_detail', None)
concert_datetime = request.POST.get('concert_datetime', None)
concert_image = request.FILES.get('concert_image', None)
upload = Concert(concert_title=concert_title, concert_player=concert_player, concert_location=concert_location, concert_detail=concert_detail, concert_image=concert_image, concert_datetime=concert_datetime)
upload.save()
return render(request, 'selectlocation.html') # location => select
concert = Concert()
concert.concert_title = request.POST.get('concert_title', None)
concert.concert_player = request.POST.get('concert_player', None)
concert.concert_location = request.POST.get('concert_location', None)
concert.concert_detail = request.POST.get('concert_detail', None)
concert.concert_datetime = request.POST.get('concert_datetime', None)
concert.concert_image = request.FILES.get('concert_image', None)
concert.save()
return redirect('/post/selectlocation/' + str(concert.id)) # location => select

# 게시글 불러오기
def detail(request, Concert_id):
concert = Concert.objects.get(id=Concert_id)
Expand All @@ -64,4 +72,4 @@ def update(request, Concert_id):
concert.concert_datetime = request.POST.get('concert_datetime', None)
concert.concert_image = request.FILES.get('concert_image', None)
concert.save()
return redirect('/post/detail/' + str(concert.id))
return redirect('/post/selectlocation/' + str(concert.id))