【发布时间】:2015-03-11 01:44:32
【问题描述】:
var latitude = document.getElementById("latitude");
var longitude = document.getElementById("longitude");
var myCenter = new google.maps.LatLng(latitude, longitude);
var marker;
function initialize()
{
var mapProp = {
center: myCenter,
zoom: 5,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
marker = new google.maps.Marker({
position: myCenter,
animation: google.maps.Animation.BOUNCE
});
marker.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
var latitude 没有得到值
这里我从下面的 ids 中获取值,
<div class="map" id="googleMap" style="width:100%;height:260px;overflow:hidden;"></div>
<div id="latitude"><?php echo $itemData['130']; ?></div>
<div id="longitude"><?php echo $itemData['131']; ?></div>
在$itemData['130'] 和$itemData['130'] 中得到正确的值,
不知道自己做错了什么?
【问题讨论】:
-
这个脚本是放在头部还是放在正文中?当它放在头部时,将代码的前 3 行移动到初始化的开头。并删除最后一行。
-
然后进行建议的修改,目前这两个元素在您尝试访问它们时都是未知的。
标签: javascript php google-maps dynamic google-maps-markers