douhuo0884 2009-09-02 18:44
浏览 48
已采纳

我的谷歌地图问题的另一个问题

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 ?

  • 写回答

2条回答 默认 最新

  • dongshan1959 2010-01-26 14:13
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘