As properties of a label in Marker are very limited. See below:
- color string: Cor do texto
- fontFamily string: Definição equivalente ao font-family do CSS
- fontSize string: Tamanho da fonte equivalente ao font-size do CSS.
- fontWeight string: Largura da letra equivalente ao font-weight do CSS
- text string: Texto no qual quer que mostre.
Example of how to use:
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
label: {text: "Placa tal", fontWeight: "bold", fontSize: "20px" }
});
But there is another option, which is to use the Markerwithlabel for V3. Download the markerwithlabel.js for your project. By doing this, just set up your label via CSS and some properties in your Marker
.
First step is to replace your new google.maps.Marker
for new MarkerWithLabel
, in this way:
var marker = new MarkerWithLabel({
//inserir propriedades
});
See below for an example of a class in CSS:
CSS:
.labelcustom{
color: #000;
font-weight: bold;
font-size: 20px;
}
JS:
Inside your Marker, insert the
labelContent
: content of label
labelAnchor
: positioning of label in relation to the centre of the Marker
labelClass
: definition of the class of label
See below for an example:
labelContent: "Placa: MLW-5973",
labelAnchor: new google.maps.Point(80, 80),
labelClass: "labelcustom"
Upshot:
Bonus:
See how I would do if it was a project of mine:
function initMap() {
var latLng = new google.maps.LatLng(49.47805, -123.84716);
var homeLatLng = new google.maps.LatLng(49.47805, -123.84716);
var map = new google.maps.Map(document.getElementById('map_canvas'), {
zoom: 12,
center: latLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var image = {
url: 'https://image.flaticon.com/icons/svg/67/67994.svg',
size: new google.maps.Size(40, 40),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(0, 32)
};
var marker = new MarkerWithLabel({
icon: image,
position: homeLatLng,
map: map,
labelContent: "MLW-5973",
labelAnchor: new google.maps.Point(30, 60),
labelClass: "labels"
});
var iw = new google.maps.InfoWindow({
content: "Home For Sale"
});
}
google.maps.event.addDomListener(window, 'load', initMap);
html,
body,
#map_canvas {
height: 500px;
width: 500px;
margin: 0px;
padding: 0px
}
.labels {
color: #010101;
background-color: #E3E3E3;
font-family: "Lucida Grande", "Arial", sans-serif;
font-weight: bold;
font-size: 16px;
text-align: center;
width: 85px;
white-space: nowrap;
border-radius: 4px;
border: 1px solid #010101;
padding: 2px;
}
<script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=geometry,places&ext=.js"></script>
<script src="https://cdn.rawgit.com/googlemaps/v3-utility-library/master/markerwithlabel/src/markerwithlabel.js"></script>
<div id="map_canvas" style="height: 400px; width: 100%;"></div>
I was able to solve it in a more manual way, but it worked. Finally, I would need to bold the font. I continue with the same previous code.
– Lucas Spielmann
@Lucasspielmann I usually use this plugin because it is easier to handle because it uses CSS. As in this example I gave, it is already in bold and with a larger font.
– viana
var Marker = new Markerwithlabel({ position: myLatLng, map: map, icon: image, Shape: Shape, label: beach[7], html: beach[0]+beach[1]+beach[2]+beach[3]+beach[4] });
– Lucas Spielmann
the icons are gone
– Lucas Spielmann
if I’m not mistaken I’m using v2 API, I guess I’ll have to go to v3
– Lucas Spielmann
we couldn’t just insert bold on the label: beach[7]?
– Lucas Spielmann
I increased the size of the image, this caused the text to fail. The goal was taken from above the image. It was good, just needed a bold to finish.
– Lucas Spielmann
Try it this way:
label: {
 text: "Placa tal",
 fontWeight: "bold"
 },
– viana
Great, and if you want to increase the font, fontsize: "20" ??
– Lucas Spielmann
@Lucasspielmann Good luck there! Just give us the dawn of life. = D Saw the bonus I put?!
– viana
Great, the bonus will study with time... Kkkk thanks again.
– Lucas Spielmann
fontsize:"30" did not give..
– Lucas Spielmann
I’m by cell editing the source KKK tomorrow we talk. Good night.
– Lucas Spielmann
@Lucasspielmann place
fontSize: "20px"
with pixel PX. hueh– viana
hey buddy, help me with this: https://answall.com/questions/258220/somar-horas-php-e-mysql Hug
– Lucas Spielmann