Skip to content Skip to sidebar Skip to footer

Generate A Google Map Using Latitude And Longitude Code Script

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 display the map on my web page

Solution 1:

Markup

<scriptlanguage=javascriptsrc='http://maps.google.com/maps/api/js?sensor=false'></script><divid="map"></div>

Javascript

functioninitialize(){
     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"
     });
} 

Solution 2:

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

#map { width: 500px; height: 400px; }

Post a Comment for "Generate A Google Map Using Latitude And Longitude Code Script"