Problems, need help? Have a tip or advice? Post it here.
7 posts Page 1 of 1
Hi, I'm trying to set the masterpage for this query code here but its only taking one value from my created posts. I need it to loop through all my created posts and display all values.
Can anybody help me out?

Here is the code :
Code: Select all
<cms:pages masterpage='maps.php' >

  <script type="text/javascript">
    // Define your locations: HTML content for the info window, latitude, longitude
   
   var locations = [
      ['<h4><a href="<cms:show k_page_link />"><cms:show k_page_title /></a></h4>',<cms:show blog_lat /> , <cms:show blog_lon /> ]
    ];
   
   
    // Setup the different icons and shadows
    var iconURLPrefix = 'http://maps.google.com/mapfiles/ms/icons/';
   
    var icons = [
      iconURLPrefix + 'red-dot.png',
      iconURLPrefix + 'green-dot.png',
      iconURLPrefix + 'blue-dot.png',
      iconURLPrefix + 'orange-dot.png',
      iconURLPrefix + 'purple-dot.png',
      iconURLPrefix + 'pink-dot.png',     
      iconURLPrefix + 'yellow-dot.png'
    ]
    var icons_length = icons.length;
   
   
    var shadow = {
      anchor: new google.maps.Point(15,33),
      url: iconURLPrefix + 'msmarker.shadow.png'
    };

    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 2,
     
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      mapTypeControl: false,
      streetViewControl: false,
      panControl: false,
      zoomControlOptions: {
         position: google.maps.ControlPosition.LEFT_BOTTOM
      }
    });

    var infowindow = new google.maps.InfoWindow({
      maxWidth: 160
    });

    var marker;
    var markers = new Array();
   
    var iconCounter = 0;
   
    // Add the markers and infowindows to the map
    for (var i = 0; i < locations.length; i++) { 
      marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map,
        icon : icons[iconCounter],
        shadow: shadow
      });

      markers.push(marker);

      google.maps.event.addListener(marker, 'click', (function(marker, i) {
        return function() {
          infowindow.setContent(locations[i][0]);
          infowindow.open(map, marker);
        }
      })(marker, i));
     
      iconCounter++;
      // We only have a limited number of possible icon colors, so we may have to restart the counter
      if(iconCounter >= icons_length){
         iconCounter = 0;
      }
    }

    function AutoCenter() {
      //  Create a new viewpoint bound
      var bounds = new google.maps.LatLngBounds();
      //  Go through each...
      $.each(markers, function (index, marker) {
        bounds.extend(marker.position);
      });
      //  Fit these bounds to the map
      map.fitBounds(bounds);
    }
    AutoCenter();
  </script>

  </cms:pages>
Hi Rachit,

I am sorry but I couldn't completely understand the question.

From what I could gather from the posted code, you have a 'maps.php' template with cloned pages having values for longitude and latitude.
The code loops through all the cloned pages of maps.php and uses the latitude and longitude values to chart markers on the map.

OK, so what is it that is not happening as expected?
I'm trying to set the masterpage for this query code here but its only taking one value from my created posts.
'one value' means what exactly? Is it listing only one cloned-page? Or is it something else that you are trying to convey?

Please let us know.
Thanks.
If you see this part of the code

Code: Select all
var locations = [
      ['<h4><a href="<cms:show k_page_link />"><cms:show k_page_title /></a></h4>',<cms:show blog_lat /> , <cms:show blog_lon /> ]
    ];


This should loop through all the entered values in my cloned pages , correct?

But on the contrary it's only taking one value(latitude and longitude value of the first post/cloned page only) out of my 5 blog posts.

I want to know how to make this take all the values instead of value from only one post.
OK, got it now.

I think you are using the cms:pages tag at the wrong place.
Instead of using the tag to surround the entire <script type="text/javascript"> .. </script> block,
please use it around only that part of the code that sets the locations i.e. like this -
Code: Select all
<script type="text/javascript">
// Define your locations: HTML content for the info window, latitude, longitude

<cms:pages masterpage='maps.php' >
var locations = [
  ['<h4><a href="<cms:show k_page_link />"><cms:show k_page_title /></a></h4>',<cms:show blog_lat /> , <cms:show blog_lon /> ]
];
</cms:pages>

..
..

Does this do the trick?
Please let us know.
@KK, I think maybe the following instead?
Code: Select all
var locations = [
    <cms:pages masterpage='maps.php'>
        [
            '<h4><a href="<cms:show k_page_link />"><cms:show k_page_title /></a></h4>',
            <cms:show blog_lat />,
            <cms:show blog_lon />
        ]
        <cms:if "<cms:not k_paginated_bottom />">,</cms:if>
    </cms:pages>
];
*facepalm*
Yes, of course, you are right cheesypoof.
Thanks for the correction.
Alright I'll try this!

Edit: Working perfectly! Thanks a lot! :)
7 posts Page 1 of 1