Yii: Any extension to implement embedded google map

前端 未结 1 1130
别跟我提以往
别跟我提以往 2021-01-29 09:35

im a yiibie, and i want to use google maps in my project just like embedded google maps. For example i want that when an ngo(in my case) is registering there ngo th

相关标签:
1条回答
  • 2021-01-29 10:09

    I don't know extension but you can easly create you map this way (in this sample there isn't the google maps key but if your app usage require this you should obtain one)

    In Your <head> section add this

    '<script src="https://maps.googleapis.com/maps/api/js?sensor=false&amp;v=3&amp;"></script>'
        <style>
          html, body, #map {
            height: 100%;
            margin: 0px;
            padding: 0px
          }
        </style>
    

    In <body> add

      <body>
         <div id="map" ></div>
      <script>
    
        var yourLat = <?= $yourLat; ?>
        var yourLng = <?= $yourLng; ?>
    
        function init() {
    
            var mapOptions = {
                zoom: 15,
                center: new google.maps.LatLng(yourLat , yourLng)
            }
    
            var mapElement = document.getElementById('map');
    
            // Create the Google Map using out element and options defined above
            var map = new google.maps.Map(mapElement, mapOptions);
    
            var myLatLng = new google.maps.LatLng(yourLat, yourLng);
            var yourMarker = new google.maps.Marker({
                position: myLatLng,
                map: map,
            });
        }
    
    
        // Google Maps Scripts
        // When the window has finished loading create our google map below
        google.maps.event.addDomListener(window, 'load', init);
      </script>
    
      ......
      </body>
    
    0 讨论(0)
提交回复
热议问题