如何使用中心每次更改的圆圈创建Google地图 第二?我试过以下:(也在 http://test.barrycarter.info/sunstuff2.html)
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0px; padding: 0px }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
function updateJ () {
j = j+0.5;
x.center = new google.maps.LatLng(j,0);
}
function initialize() {
var myLatLng = new google.maps.LatLng(0,0);
var myOptions = {zoom:2,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.TERRAIN
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
j = 20.18
x = new google.maps.Circle({
center: new google.maps.LatLng(j,-18.5037550725315),
radius: 10018760,
map: map,
strokeWeight: 2,
fillOpacity: 0.2,
fillColor: "#ffffff"
});
}
</script>
</head>
<body onload="initialize(); updateJ(); setInterval('updateJ()', 1000)">
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>
Firebug确认'j'每秒都会增加,但这一行:
x.center = new google.maps.LatLng(j,0);
什么都不做。是否有google.maps.PleaseRedrawThisObjectBecauseIHaveChangedStuff方法?
答案 0 :(得分:1)
API函数通常不支持手动设置属性。尝试使用getter / setter函数,如下所示:
x.setCenter(new google.maps.LatLng(j, 0));