Thursday 17 July 2014

Google Map - Add a marker

Google Map - Add a marker to the Google map
The Marker constructor creates a marker in Google Map. Position property must be set for the marker to display.
Add the marker to the map by using the setMap() method.



<script src="//maps.google.com/maps/api/js?sensor=true"></script>
<script>
    /** Add lat/lng of your location **/
    var myCenter2=new google.maps.LatLng(51.508742,-0.120850);

    function initialize2()
    {
        var mapProp2 = {
            center:myCenter2,
            zoom:5,
            mapTypeId:google.maps.MapTypeId.ROADMAP
        };

        var map=new google.maps.Map(document.getElementById("googleMapId2"),mapProp2);

        var marker2=new google.maps.Marker({
            position:myCenter2,
            animation:google.maps.Animation.BOUNCE
        });

        marker2.setMap(map);
    }
    google.maps.event.addDomListener(window, 'load', initialize2);
</script>
<div id="googleMapId2" style="height: 500px; width: 800px;">
</div>