Use the offset
argument, and only get 1 result:
global $my_page_offset;
if(!isset($my_page_offset))
$my_page_offset = 0;
$pages = get_pages(array(
'child_of' => $post->ID,
'sort_column' => 'menu_order',
'offset' => $my_page_offset,
'number' => 1,
));
$my_page_offset++;
...
I’m assuming here that you don’t have much control over these loops, because you’re doing them multiple times. This is why the global variable…
Last try:
After var infowindow;
add this:
<?php
$pages = get_pages(array('child_of' => $post->ID, 'sort_column' => 'menu_order'));
$data = array();
foreach($pages as $post){
setup_postdata($post);
$fields = get_fields();
$data[] = '<p>'.$fields->company_name.'</p>';
}
wp_reset_query();
// the js array
echo 'var marker_data = ["'.implode('","', $data).'"];';
?>
Now infowindow.setContent should be:
infowindow.setContent(marker_data[i]);