Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Populating Google Map with Markers and infoboxes  using Coldfusion

Posted on 2014-01-12
4
Medium Priority
?
908 Views
Last Modified: 2014-01-20
Here is the Map Code.
<cfoutput query="getfeaturedlistings">#latitude#</cfoutput>

Open in new window

 is is working and returning LAT LONG to populate the map with markers..My problem is that I cant have an associated info box with each marker.

in
var myOptions = {
	        content: '<div class="infobox"><div class="image"><img src="http://www.mydomain.com/images/forsale.png" alt=""></div><div class="title"><a href="detail.html">1041 Fife Ave</a></div><div class="area"><span class="key">Area:</span><span class="value">200m<sup>2</sup></span></div><div class="price">€450 000.00</div><div class="link"><a href="detail.html">View more</a></div></div>',

Open in new window

I want to have different data for each marker's info box.

How do I do this?



<script type="text/javascript">   
      
    

function LoadMap() {
	var locations = new Array(
        <cfoutput query="getfeaturedlistings">#latitude#</cfoutput>
        );
	var markers = new Array()
	var mapOptions = {
		center: new google.maps.LatLng(49.3536595, -123.2449326),
		zoom: 12,
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		scrollwheel: false
    };



    var map = new google.maps.Map(document.getElementById('map'), mapOptions);

    $.each(locations, function(index, location) {
        var marker = new google.maps.Marker({
            position: new google.maps.LatLng(location[0], location[1]),
            map: map,
            icon: 'http://html.realia.byaviators.com/assets/img/marker-transparent.png'
        });

	    
		var myOptions = {
	        content: '<div class="infobox"><div class="image"><img src="http://www.mydomain.com/images/forsale.png" alt=""></div><div class="title"><a href="detail.html">1041 Fife Ave</a></div><div class="area"><span class="key">Area:</span><span class="value">200m<sup>2</sup></span></div><div class="price">€450 000.00</div><div class="link"><a href="detail.html">View more</a></div></div>',
	        disableAutoPan: false,
	        maxWidth: 0,
	        pixelOffset: new google.maps.Size(-146, -190),
	        zIndex: null,
	        closeBoxURL: "",
	        infoBoxClearance: new google.maps.Size(1, 1),
	        position: new google.maps.LatLng(location[0], location[1]),
	        isHidden: false,
	        pane: "floatPane",
	        enableEventPropagation: false
	    };
		
	    marker.infobox = new InfoBox(myOptions);
		marker.infobox.isOpen = false;
		
		
	    var myOptions = {
	        draggable: true,
			content: '<div class="marker"><div class="marker-inner"></div></div>',
			disableAutoPan: true,
			pixelOffset: new google.maps.Size(-21, -58),
			position: new google.maps.LatLng(location[0], location[1]),
			closeBoxURL: "",
			isHidden: false,
			// pane: "mapPane",
			enableEventPropagation: true
	    };
	    marker.marker = new InfoBox(myOptions);
		marker.marker.open(map, marker);
		markers.push(marker);

        google.maps.event.addListener(marker, "click", function (e) {
            var curMarker = this;

            $.each(markers, function (index, marker) {
                // if marker is not the clicked marker, close the marker
                if (marker !== curMarker) {
                    marker.infobox.close();
                    marker.infobox.isOpen = false;
                }
            });


            if(curMarker.infobox.isOpen === false) {
                curMarker.infobox.open(map, this);
                curMarker.infobox.isOpen = true;
                map.panTo(curMarker.getPosition());
            } else {
                curMarker.infobox.close();
                curMarker.infobox.isOpen = false;
            }

        });
    });
}

function InitMap() {
	google.maps.event.addDomListener(window, 'load', LoadMap);
}
</script>

Open in new window

0
Comment
Question by:izweig
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 38

Accepted Solution

by:
Tom Beck earned 2000 total points
ID: 39776489
Does the locations array contain the additional information? For example, is it just a matter of accessing different indexes in the array?

'<div class="infobox"><div class="image"><img src="http://www.mydomain.com/images/forsale.png" alt=""></div><div class="title"><a href="detail.html">' + location[2] + '</a></div><div class="area"><span class="key">Area:</span><span class="value">200m<sup>' + location[3] + '</sup></span></div><div class="price">' + location[4] + '</div><div class="link"><a href="detail.html">View more</a></div></div>'

If not then where is the additional information coming from?
0
 

Author Comment

by:izweig
ID: 39776880
Thanks. That causes all the infoboxes to open at the same time on any marker that is clicked.
Perhaps my problem is in my marker array?
This is the generated code:
var locations = new Array
([49.3446158,-123.2097986],[49.3514140,-123.2605710],[49.3522052,-123.1074731]
 );

Open in new window

0
 
LVL 38

Expert Comment

by:Tom Beck
ID: 39778984
Is this resolved?
0
 

Author Comment

by:izweig
ID: 39795551
Yes thanks!!
0

Featured Post

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
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…
Suggested Courses

722 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