2009-09-02 56 views
0

我已經問過兩個先前的問題,從Lightroom創建的XML文件中放置多個標記,這些標記必須以度數而不是度,分,秒進行轉換。 這部分我管理,但然後...我的谷歌地圖問題的另一個問題

在上一個問題的答案是非常豐富的信息,但這是我的編程(第一個項目),我只是不能解決它的設計技巧。

問題是我想顯示多個標記。

的完整代碼:

<?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:[email protected]/GEOCODES'); 
    // enter YOUR Google Map Key 
    $map->setAPIKey('ABQIAAAAiA4e9c1IW0MDrtoPQRaLgRQmsvD_kVovrOh_CkQEnehxpBb-yhQq1LkA4BJtjWw7lWmjfYU8twZvPA'); 

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

的問題是,在 「$ MAP-> addMarkerByCoords($ LonArray,$ LatArray,$ albuArray,$ guaArray);」只顯示4個數組中的最後一個值。

因此,只有一個標記創建。

例如$ guaArray的輸出(print_r)是IMG_3308IMG_3309IMG_3310IMG_3311IMG_3312(圖片的文件名的5個名稱)。

從 'GoogleMapAPI.class.php' 功能addMarkersByCoords是這樣的:

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; 
    } 

我希望有人能幫助我嗎?

回答

0

您必須創建的foreach上面的谷歌地圖的新實例

這樣

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

foreach() 
{ 
} 

現在你正在創建的每一個迴路與上次座標新地圖

+0

如何粘貼代碼示例? – Marco 2010-01-29 11:18:38

+0

已經找到了:) – Marco 2010-01-29 11:19:13

0

foreach環未完成annything有用:

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

$LonArray距離$Lonarr數組只有一個元素。我認爲foreach循環將數組的每個元素添加到一個大字符串($ LonArray)中。

+0

當我做的print_r $ guaArray的輸出是IMG_3308IMG_3309IMG_3310IMG_3311IMG_3312(文件名的5個名稱來自照片)。 所以數組被填充或應該做數組[0],[1],[2]等等,等等? – Plumbum7 2009-09-03 17:19:31

+1

這不是一個數組。如果是這樣,print_r會顯示如下:「Array([0] => x [1] => y [2] => z)」 – 2009-09-03 17:42:23

+0

好的,我必須在這方面努力。 – Plumbum7 2009-09-03 18:42:12