Saturday, November 8, 2014

Google Map Simple Info windows

Below code can be used to bring up a sample info window

function initialize() {
                        var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
                        var mapOptions = {
                            zoom: 4,
                            center: myLatlng
                        };
                        
                        var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
                        
                        var contentString = 'sample text';
                        
                        var infowindow = new google.maps.InfoWindow({
                                                                    content: contentString
                                                                    });
                                                                    
                                                                    var marker = new google.maps.Marker({
                                                                                                        position: myLatlng,
                                                                                                        map: map,
                                                                                                        title: 'Uluru (Ayers Rock)'
                                                                                                        });
                                                                                                        google.maps.event.addListener(marker, 'click', function() {
                                                                                                                                      infowindow.open(map,marker);
                                                                                                                                      });
                    }
                

                google.maps.event.addDomListener(window, 'load', initialize);

References:
https://developers.google.com/maps/documentation/javascript/examples/infowindow-simple

No comments:

Post a Comment