Yii: Any extension to implement embedded google ma

2020-05-09 18:50发布

问题:

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>