I am trying to put a label on a polygon drawn via the google maps api.
the result of my getPolygons.php ajax call looks like 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, // the CSS class for the label
labelInBackground: false
});
});
}
I have tried using markerswithlabel.js
I include this script:
<script src="https://maps.googleapis.com/maps/api/js?key=API_KEY&signed_in=true&libraries=drawing&callback=initMap" defer></script>
and the standard
<script src='markerLabel.js'></script>
but when i include markerLabel.js I get this error:
Uncaught ReferenceError: google is not defined
I am trying to do something like this: