[英]parse xml with php , google maps api v3 markers
我正在嘗試找到一種在php文件中使用函數初始化的方法。我使用file_get_contents解析xml文件
$xml = file_get_contents('http://www.123.org/upload/123.xml');
include 'xml_regex.php';
$news_items = element_set('item', $xml);
foreach($news_items as $item) {
$description = value_in('description', $item);
$glat = value_in( 'glat', $item );
$glon = value_in( 'glon', $item );
$item_array[] = array(
'description' => $description,
'glat'=>$glat,
'glon'=>$glon
);
}
函數初始化
</script>
function initialize() {
var mapOptions = {
zoom: 6,
center: new google.maps.LatLng( 38.822590,24.653320 )
};
var map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);
<?php foreach ( $item_array as $item ) {
//how can i use this lines inside the loop?
//var latlng = new google.maps.LatLng(parseFloat("<?php $glat ?>"),
//parseFloat("<?php $glon ?>"));
//alert (latlng);
//also inside the loop i wanna use the createMarker funciton
}?>
</script>
有任何想法嗎?
終於我找到了方法!只需引用代碼即可,也許將來會對某人有所幫助!
<?php foreach ( $item_array as $item ) : ?>
var latlng = new google.maps.LatLng(parseFloat(<?php echo $item['glat']; ?>),
parseFloat(<?php echo $item['glon']; ?>));
if ( '<?php echo $item["temp"]; ?>' <= "1 °C" ) {
var marker = createMarker( latlng,cold );
}
function createMarker( latlng,cold ) {
var marker = new google.maps.Marker({
position: latlng,
map: map,
icon: cold
});
return marker;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.