Could someone please describes me, where is problem and how the code could be fixed?
This is not working :
function initialize() {
var b = new google.maps.LatLng(49.190033, 16.6150523); var Copt = {center:b, map: map, radius: 1000};
var mapOptions = { zoom: 13, center: b, mapTypeId: google.maps.MapTypeId.ROADMAP }
var map = new google.maps.Map(document.getElementById("map_canvas"),mapOptions);
cir();
//var C = new google.maps.Circle(Copt);C.setMap(map);
}
function cir(){
var C = new google.maps.Circle(Copt); C.setMap(map);
}
But when I put the content of the function cir() inside initialize, its working:
here
function initialize() {
var b = new google.maps.LatLng(49.190033, 16.6150523);
var Copt = {center:b, map: map, radius: 1000};
var mapOptions = { zoom: 13, center: b, mapTypeId: google.maps.MapTypeId.ROADMAP }
var map = new google.maps.Map(document.getElementById("map_canvas"),mapOptions);
//cir();
var C = new google.maps.Circle(Copt);C.setMap(map);
}
I think, it has something to do with the part <body onload="initialize()"> but realy dont understand what to do , how to put a function outside of initialize and how is this working.
<div id="map_canvas" style="width:100%; height:100%"></div>
Could you please create a short example of function for creating circle and call it from initialize ?
I think the problem you’re having is, your
Cfunction doesn’t have themapvariable in scope. Try this:Passing the
mapparameter to yourdrawCircle()function means it can then use it. I’m not familiar with theCircleobject, but you should be able to implement your code from here.