Solved

Google Map with markers not displaying

Posted on 2014-10-23
2
152 Views
Last Modified: 2014-10-24
Hi, I have the following code that should display a map with the markers on it of 5 local businesses.

I've played around for a while but nothing is appearing at all, even alerts()?

Anyone able to take a look and correct any squiffy code please?

Regards
Neil
        
        <script type="text/javascript" src="//maps.google.com/maps/api/js?sensor=false"></script>
        <script type="text/javascript">
        
		var infowindow = null;
			
    
		var centerMap = new google.maps.LatLng(51.421196,0.392989);

		var myOptions = {
			zoom: 7,
			center: centerMap,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		}

		var map = new google.maps.Map(document.getElementById("map_canvas_local_businesses"), myOptions);
	
		setMarkers(map, sites);
		
		infowindow = new google.maps.InfoWindow({
			content: "loading..."
		});						      
		
		var sites = [["Dok Electrical","51.373516","0.576815","Elmfield, Gillingham, Kent"], ["Bee Bright Tuition","51.430527","0.399807","Rochester Road, Gravesend, Kent"], ["M and D Plasterers","51.315117","0.393089","Chapel Close, Ryarsh, West Malling, Kent"], ["Halloween Goodies Bags","51.422668","0.376006","Gloucester Road, Gravesend, Kent"], ["Mike's Kitchens","51.440453","0.342623","Plane Avenue, Northfleet, Gravesend, Kent"]];		
        function setMarkers(map, markers) {
			    
            for (var i = 0; i < markers.length; i++) {
                var sites = markers[i];
                var siteLatLng = new google.maps.LatLng(sites[1], sites[2]);
				 
                var marker = new google.maps.Marker({
                    position: siteLatLng,
                    map: map,
                    title: sites[0],
                    zIndex: i,
                    html: '<div style="min-height:90px;min-width:180px;text-align:right;"><h3>test</p><div>'
                });
				
				
                var contentString = "Some content";
    
                google.maps.event.addListener(marker, "click", function () {
                    infowindow.setContent(this.html);
                    infowindow.open(map, this);
                });
            }
        }
		
		 
 

    </script>
    

	<div id="map_canvas_local_businesses" style="width:600px;height:400px;"></div>

Open in new window

0
Comment
Question by:NeilT
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40400460
Move your script/s after the map div - you are trying to initiate the map before it exists

As for the markers - nothing is defined for sites
0
 
LVL 3

Author Closing Comment

by:NeilT
ID: 40401278
Annoyingly simple. Thanks Gary :)
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now