开发者

Google map w/ circle that changes every second?

How do I create a google map with a circle whose center changes every second? I tried the below: (also at 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 confirms that 'j' increases every second开发者_如何学Python, but this line:

x.center = new google.maps.LatLng(j,0); 

does nothing. Is there a google.maps.PleaseRedrawThisObjectBecauseIHaveChangedStuff method?


The API functions generally don't support manually setting properties. Try using the getter/setter functions like so:

x.setCenter(new google.maps.LatLng(j, 0));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜