Yii: Any extension to implement embedded google map

不想你离开。 提交于 2019-12-02 13:19:27

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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!