javascript - Draw rectangle from function Google Maps Api -


i've got project want divide world map regular grid highlight parts of grid

i've managed hack example draw 20x20 rectangle on google world map

 function initmap() {      var map = new google.maps.map(document.getelementbyid('map'), {     zoom: 1,     center: {lat: 60.18, lng: 24.93},     maptypeid: google.maps.maptypeid.terrain   });  var rectangle = new google.maps.rectangle({ strokecolor: '#ff0000', strokeopacity: 0.8, strokeweight: 2, fillcolor: '#ff0000', fillopacity: 0.35, map: map, bounds: {    west: 180, north:0, east: -160, south: 20 } });      initmap(); 

http://jsfiddle.net/6zea831p/4/

but i'd turn function many rectangles can highlighted depending on other parts of script. i'm not having success turning function though. start

function drawrec(w, n, e, s){   var coords = new google.maps.latlngbounds(         new google.maps.latlng(w, n),         new google.maps.latlng(e, s))  var rectangle = new google.maps.rectangle({    strokecolor: '   #ff00ff',    strokeopacity: 0.8,    strokeweight: 1,    fillcolor: ' #ff00ff',    fillopacity: 0.35,     bounds: coords,     map: map    });    } 

i error of "invalidvalueerror: setmap: not instance of map" in console.

declare 'map' var outside 'initmap()' function make global across script tag

var map;  function initmap() {     map = new google.maps.map(document.getelementbyid('map'), {     ...     ... }  function drawrec(w, n, e, s){     ... } 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -