javascript - google maps API polygon labels -


i trying put label on polygon drawn via google maps api.

the result of getpolygons.php ajax call looks this:

var trianglecoords = [     {lat:38.88154,lng: -77.02880},     {lat:38.83863,lng:-77.02760},     {lat:38.83917,lng:-77.07292},     {lat:38.84251,lng: -77.12098},     {lat:38.86951,lng:-77.13575},     {lat:38.88769, lng:-77.05404} ]; 

code:

$.ajax({     type:"get",     url:"getpolygons.php",     datatype:"json",     success:function(result){             $.each(result,function(e,i){             var trianglecoords = [];             var color = i.color;             $.each(i.points,function(ee,ii){                     var lat = parsefloat(ii.lat);                     var lon = parsefloat(ii.lon);                     trianglecoords.push({lat:lat,lng:lon});             });             var bermudatriangle = new google.maps.polygon({                  paths: trianglecoords,                  strokecolor: '#ff0000',                  strokeopacity: 0.8,                  strokeweight: 2,                  fillcolor: color,                   fillopacity: 0.35             });             bermudatriangle.setmap(map);    var pos = new google.maps.latlng(lat,lon);   var marker = new markerwithlabel({           position: pos,           map: map,           labelanchor: new google.maps.point(3, 30),          labelclass: sclass, // css class label           labelinbackground: false           });             });      } 

i have tried using markerswithlabel.js

i include script:

 <script src="https://maps.googleapis.com/maps/api/js?key=api_key&signed_in=true&libraries=drawing&callback=initmap" defer></script> 

and standard

 <script src='markerlabel.js'></script> 

but when include markerlabel.js error:

 uncaught referenceerror: google not defined 

i trying this:

my example

you loading google maps javascript api asynchronously. markerwithlabel library depends on that, needs loaded after google maps javascript api has completed loading.

either load library asynchronously after google maps javascript api or load them both inline in correct order.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -