Показать сообщение отдельно
  #3 (permalink)  
Старый 18.05.2019, 19:15
Интересующийся
Отправить личное сообщение для Vladiiimir Посмотреть профиль Найти все сообщения от Vladiiimir
 
Регистрация: 18.05.2019
Сообщений: 19

рони,
Скажите, а в каком части кода должны быть объявлены "var map, marker"?
Извините за возможно тупой вопрос, я только начал изучать javascript.
Я пытаюсь сделать вот так, но карта непрогружается вообще:
<html>
  <head>
    <title>Simple Map</title>
    <meta charset="utf-8">
    <style>
      /* Always set the map height explicitly to define the size of the div
       * element that contains the map. */
      #map {
        height: 50%;
      }
      /* Optional: Makes the sample page fill the window. */
      html, body {
        height: 100%;
      }
    </style>
   
     <script>
      function initMap() {
          map = new google.maps.Map(document.getElementById('map'), {
          center: new google.maps.LatLng(51.754207,55.106578),
          zoom: 8
        });
      }
    </script>
    var map, marker;
    <script>
        function UpdateGoogleMap(latitude=51.754207, longitude=55.106578) {
            map.setCenter(
                {lat: latitude,
                 lng: longitude}
            );
            marker && marker.setMap(null);
            marker=new google.maps.marker({
                position:{
                 lat: latitude,
                 lng: longitude
                },
            map: map,
            title: 'Это здесь'
            });
     };
      </script>
      <!-- -->
      <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCWH__g2XMzhes7PIk-8v2MbBSZTgMnBSg&callback=UpdateGoogleMap"
      async defer></script>
      
  </head>
  <body>
        <form name="info"> 
                Широта: <input type="text" name="xfirst" align="left" size=20><br><br>
                Долгота: <input type="text" name="xend" align="left" size=20><br><br>

                <input type="button" value="Построить" name="buttonDraw" align="center" size=15 onclick="UpdateGoogleMap(+xfirst.value,+xend.value)"><br>
        </form>

        <div id="map">               
        </div>
    
  </body>
</html>
Ответить с цитированием