map.ejs 5.1 KB
<html>
  <head>
    <title><%= title %></title>
    <link rel='stylesheet' href='/stylesheets/style.css'/>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBTR69UvS1403rvBcM64_8nlzpKLv23RIE&libraries=places"></script>
    <script>

            //표시하기 버튼 눌렀을 때 post보내는 함수

            function forming() {


              console.log(place)


             if(confirm("맛집견문록에 기록하겠습니까?")){

               document.forms["userform"].submit();
               return true;
             }else{
               return false;
             }

           }


        function initMap(latitude, longitude) {
          var center = {lat: latitude, lng: longitude};
          map = new google.maps.Map(document.getElementById('map'), {
            zoom: 15,
            center: center
          });

          var marker = new google.maps.Marker({
            position: center,
            map: map
          });

          infowindow = new google.maps.InfoWindow();

          var service = new google.maps.places.PlacesService(map);

          service.nearbySearch({
            location: center,
            radius: 1000,
            type: ['restaurant']
          }, callback);
          function callback(results, status) {
            if (status === google.maps.places.PlacesServiceStatus.OK) {
              for (var i = 0; i < results.length; i++) {
                createMarker(results[i]);
              }
            }
          }

          function createMarker(place) {
            var image1 = 'http://localhost:3000/images/restaurant_1.png'
            var image2 = 'http://localhost:3000/images/restaurant_2.png'

            var placeLoc = place.geometry.location;
            var marker1 = new google.maps.Marker({
              map: map,
              position: place.geometry.location,
              icon: image1
            });
            var marker2 = new google.maps.Marker({
              map: map,
              position: place.geometry.location,
              icon: image2
            });
            marker2.setMap(null);

            var contentString = '<div id="content">'+
                                '<div id="siteNotice">'+
                                '</div>'+
                                '<h1 id="firstHeading" class="firstHeading">'+place.name+'</h1>'+
                                '<div id="bodyContent">'+
                                '<p>주소: '+place.vicinity+'<br/>'+
                                '<a href="#" onclick="forming();">'+
                                '표시하기</a> '+
                                '</p>'+
                                '</div>'+
                                '</div>';




            google.maps.event.addListener(marker1, 'click', function(e) {
              //console.log(place)





              var infowindow = new google.maps.InfoWindow({
                content: contentString,
                maxWidth: 300
              });
              infowindow.open(map, this);
              //marker1.setMap(null);
              //marker2.setMap(map);
              console.log('<%=user.username%>');


//            console.log(document.getElementsByName('placeaddress').value);



            });
            google.maps.event.addListener(marker2, 'click', function() {
              var infowindow = new google.maps.InfoWindow({
                content: contentString,
                maxWidth: 300
              });
              infowindow.open(map, this);
            });
          }

        }

        $(document).ready(function() {

          //  $('.sidenav').hide();

          $('#show').click(function() {

                  //$('.sidenav').slideToggle("fast");
                  $this = $(this);
                  $nav = $('#mynav');
                  $nav.toggleClass('open');
          });

          $("input[name=first_name]");

          if("geolocation" in navigator) {
            navigator.geolocation.getCurrentPosition(function(position) {
               //console.log(position.coords.latitude)
               //findShops(position.coords.latitude, position.coords.longitude);
               initMap(position.coords.latitude, position.coords.longitude);
            });
          } else {

          }
      });


  </script>


  <div id ="show">clickmenu</div>
  <div id ="maintitle">맛집견문록</div>

  <div id ="mynav">
     <ul class="sidenav">
          <li><a class="active" href="home">home</a></li>
          <li><a href="map">맛집도장찍기</a></li>
          <li><a href="mybook">견문록확인</a></li>
     </ul>
</div>


    <div id = "title"> </div>

    <div id ="content">
      <div id="map"></div>
      <div id="popup"></div>
      <div id="form">
        <form name="userform" method="POST" action="/map">
          <input type="hidden" name="userid"/>
          <input type="hidden" name="placeid"/>
          <input type="hidden" name="placename"/>
          <input type="hidden" name="placeaddress"/>
        </form>


      </div>
    </div>

    <div id ="footer"></div>

  </body>

</html>