Yii: Any extension to implement embedded google map

瘦欲@ 提交于 2019-12-04 07:27:41

问题


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 they could give there address, type of map etc (just like in embedded google map) on the map so that people visiting that ngo page could easily locate that ngo and can get a route to that ngo, i have no idea of how and where using these google maps, please help me, thank you.


回答1:


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>


来源:https://stackoverflow.com/questions/33800640/yii-any-extension-to-implement-embedded-google-map

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