【发布时间】:2013-10-16 17:52:47
【问题描述】:
我在谷歌地图中放置多个标记时遇到问题。这是我的代码。它在页面重新加载期间仅显示一个标记,并且当页面完全加载时地图不显示。javascript code:
<head>
<script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false">
</script>
<script>
function initialize(lat,lon)
{
var myCenter=new google.maps.LatLng(lat,lon);
var mapProp = {
center:myCenter,
zoom:9,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
var marker=new google.maps.Marker({
position:myCenter,
});
marker.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="googleMap" style="width:500px;height:380px;"></div>
</body>
</html>
php code:
<?php
require_once 'geocode.php';
$addarray=array(0=>'a, ahmedabad,india',1=>'b,ahmedabad,india');
foreach($addarray as $add)
{
// define the address and set sensor to false
$opt = array (
'address' => urlencode($add),
'sensor' => 'false'
);
// now simply call the function
$result = getLatLng($opt);
// if status was successful, then print the lat/lon ?
if ($result['status']) {
echo '<pre>';
?>
<script>
initialize(<?php echo $result['lat'];?>,<?php echo $result['lon'];?>);
</script>
<?php
echo '</pre>';
}
}
?>
首先我根据地址得到了纬度和经度,然后我调用了 javascript 函数来放置标记。但是缺少某些东西或产生问题。
提前致谢。
【问题讨论】:
-
不能用这种方法放置marker吗?
-
我的问题是差异。根据您建议的 quetion.beacause javascript 中有一系列位置。我使用带有 php.so 的 foreach 循环逐个传递位置。所以这两个问题中的问题可能相似,但方法不同。所以我认为它不是重复的。
-
您的问题不够清楚。 this one (Google maps with multiple markers from a php array) 呢?你做过研究吗?
-
感谢您的建议。
标签: javascript php google-maps google-maps-api-3