这可能是显而易见的……但我看不到。以下代码对除 marker.setPosition 操作之外的所有内容均按预期工作:
<head>
<title>Test Simulation</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=x&sensor=false">
</script>
<script type="text/javascript">
var marker = null;
var myLatlng = null;
var map = null;
var image = null;
var mapOptions = null
function movemarker()
{
xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","http://x.com/x13/?testloc=1",false);
xmlhttp.send();
var data = xmlhttp.responseText;
vals = data.split(',');
latv = parseFloat(vals[0]);
lonv = parseFloat(vals[1]);
myLatlng = new google.maps.LatLng(latv,lonv);
var fld = document.getElementById('before_map');
fld.innerText = ' ' + 'lat:' + latv + ', lon: ' + lonv + ' ' + myLatlng.toString();
marker.setPosition = myLatlng;
}
function initialize()
{
myLatlng = new google.maps.LatLng(44.809122,-36.650391);
mapOptions =
{
center: myLatlng,
zoom: 3,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"),
mapOptions);
image = 'http://x.com/x_icon.gif';
marker = new google.maps.Marker(
{
position: myLatlng,
map: map,
icon: image,
title:"Hello World!"
})
window.setInterval("movemarker()",5000);
}
</script>
</head>
<body onload="initialize(); ">
<div id="before_map">Test area...</div>
<div id="map_canvas" style="align:right; width:600; height:500"></div>
“before_map”测试区域显示新的纬度和经度值——每 5 秒更新一次。
我已经根据类似问题的答案进行了调整,但我仍然卡住了。