views:

132

answers:

2

I have asked in two earlier questions to place multiple markers from a XML file created from Lightroom, which had to be tranformed in degrees instead of Degrees,Minutes,Seconds. This part i managed but then...

The answers in the previous question were very informative but it's my poor skill of programming (first project) that i just cannot manage to solve it.

The problem is i want to show multiple markers.

the complete code:

    <?php
    require('GoogleMapAPI.class.php');

 $objDOM = new DOMDocument("1.0", 'utf-8');

 $objDOM->preserveWhiteSpace = false;

 $objDOM->load("googlepoints.xml"); //make sure path is correct

 $photo = $objDOM->getElementsByTagName("photo");
 foreach ($photo as $value) {

    $album = $value->getElementsByTagName("album");
    $albu = $album->item(0)->nodeValue;

    $description = $value->getElementsByTagName("description");
    $descriptio = $description->item(0)->nodeValue;

    $title = $value->getElementsByTagName("title");
    $titl = $title->item(0)->nodeValue;

    $link = $value->getElementsByTagName("link");
    $lin = $link->item(0)->nodeValue;

    $guid = $value->getElementsByTagName("guid");
    $gui = $guid->item(0)->nodeValue;

    $gps = $value->getElementsByTagName("gps");
    $gp = $gps->item(0)->nodeValue;

 $Deglon = str_replace("'", "/", $gp);
 $Deglon = str_replace("°", "/", $Deglon);
 $Deglon = str_replace("", "/", $Deglon);


 $str = $Deglon;

 $arr1 = str_split($str, 11);

 $date = $arr1[0];  // Delimiters may be slash, dot, or hyphen
 list ($latdeg, $latmin, $latsec, $latrichting) = split ('[°/".-]', $date);

 $Lat = $latdeg + (($latmin + ($latsec/60))/60);

  $latdir = $latrichting.$Lat;
 If (preg_match("/N /", $latdir)) {$Latcoorl = str_replace(" N ", "+",$latdir);}
        else {$Latcoorl = str_replace ("S ", "-",$latdir);}
 //$Latcoord=$Latcoorl.",";

 $date1 = $arr1[1];  // Delimiters may be slash, dot, or hyphen
 list ($londeg, $lonmin, $lonsec, $lonrichting) = split ('[°/".-]', $date1);

 $Lon = $londeg + (($lonmin + ($lonsec/60))/60);

 $londir = $lonrichting.$Lon;

 If (preg_match("/W /", $londir)) {$Loncoorl = str_replace("W ", "+",$londir);}
        else {$Loncoorl = str_replace ("E", "-",$londir);}


$Lonarr = array($Loncoorl);
foreach ($Lonarr as &$LonArray);

$Latarr = array($Latcoorl);
foreach ($Latarr as &$LatArray);

$titarr = array($titl);
foreach ($titarr as &$titArray);

$guarr = array($gui);
foreach ($guarr as &$guaArray);

$albuarr = array($albu);
foreach ($albuarr as &$albuArray);

print_r ($LonArray);
print_r ($LatArray);

print_r ($guaArray);
print_r ($albuArray);


    $map = new GoogleMapAPI('map');
    // setup database for geocode caching
 // $map->setDSN('mysql://USER:PASS@localhost/GEOCODES');
    // enter YOUR Google Map Key
    $map->setAPIKey('ABQIAAAAiA4e9c1IW0MDrtoPQRaLgRQmsvD_kVovrOh_CkQEnehxpBb-yhQq1LkA4BJtjWw7lWmjfYU8twZvPA');   

  $map->addMarkerByCoords($LonArray,$LatArray,$albuArray,$guaArray);
} 
?>

The problem is that the "$map->addMarkerByCoords($LonArray,$LatArray,$albuArray,$guaArray);" only shows the last value's from the 4 arrays.

And there fore there is only one marker created.

The output (print_r) of for example the $guaArray is IMG_3308IMG_3309IMG_3310IMG_3311IMG_3312 (5 name's of filename's from photographs).

The function addMarkersByCoords from the 'GoogleMapAPI.class.php' is like this:

function addMarkerByCoords($lon,$lat,$title = '',$html = '',$tooltip = '') {
        $_marker['lon'] = $lon;
        $_marker['lat'] = $lat;
        $_marker['html'] = (is_array($html) || strlen($html) > 0) ? $html : $title;
        $_marker['title'] = $title;
        $_marker['tooltip'] = $tooltip;
        $this->_markers[] = $_marker;
        $this->adjustCenterCoords($_marker['lon'],$_marker['lat']);
        // return index of marker
        return count($this->_markers) - 1;
    }

I hope that someone can help me ?

A: 

Your foreach loops aren't accomplishing annything useful:

$Lonarr = array($Loncoorl);
foreach ($Lonarr as &$LonArray);

$LonArray is just one element from the $Lonarr array. I think the foreach loop is adding each element of the array onto one big string ($LonArray).

Chris B
When i do print_r $guaArray the output is IMG_3308IMG_3309IMG_3310IMG_3311IMG_3312 (5 name's of filename's from photographs).So the array is filled or should it do array [0], [1], [2] etc, etc?
Plumbum7
It's not an array. If it was, print_r would show something like this: "Array ( [0] => x [1] => y [2] => z )"
Chris B
OK i have to work on that.
Plumbum7
A: 

You must create the new instance of the google map above the foreach

like this

    $map = new GoogleMapAPI('map');
    // setup database for geocode caching
 // $map->setDSN('mysql://USER:PASS@localhost/GEOCODES');
    // enter YOUR Google Map Key
    $map->setAPIKey('ABQIAAAAiA4e9c1IW0MDrtoPQRaLgRQmsvD_kVovrOh_CkQEnehxpBb-yhQq1LkA4BJtjWw7lWmjfYU8twZvPA');   

foreach ()
{
}

now you are creating every loop a new map with the last coord

Marco
How can i paste a code example ?
Marco
Already found :)
Marco