Generate a google map using latitude and longitude code script

前端 未结 2 1842
傲寒
傲寒 2021-01-06 14:26

I need to generate a google map with a marker.

I have the latitude and longitude code.

There\'s lots of scripts around but what is the quickest way to displa

相关标签:
2条回答
  • 2021-01-06 14:41

    The code is adding some invisible content to the map div. To view it, we need to add CSS:

    #map { width: 500px; height: 400px; }
    
    0 讨论(0)
  • 2021-01-06 14:50

    Markup

    <script language=javascript src='http://maps.google.com/maps/api/js?sensor=false'></script>
    <div id="map"></div>
    

    Javascript

    function initialize(){
         var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
         var myOptions = {
             zoom: 4,
             center: myLatlng,
             mapTypeId: google.maps.MapTypeId.ROADMAP
             }
          map = new google.maps.Map(document.getElementById("map"), myOptions);
          var marker = new google.maps.Marker({
              position: myLatlng, 
              map: map,
          title:"Fast marker"
         });
    } 
    
    google.maps.event.addDomListener(window,'load', initialize);
    

    Jquery

    $(document).ready(function (){
         var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
         var myOptions = {
             zoom: 4,
             center: myLatlng,
             mapTypeId: google.maps.MapTypeId.ROADMAP
             }
          map = new google.maps.Map($('#map'), myOptions);
          var marker = new google.maps.Marker({
              position: myLatlng, 
              map: map,
          title:"Fast marker"
         });
    } 
    
    0 讨论(0)
提交回复
热议问题