To add a label above the starting marker A and ending marker B on a Google Map using the JavaScript API, you can use a MarkerWithLabel library. Here's an example code snippet to get you started:
// Add Starting Marker A
var markerA = new MarkerWithLabel({
position: {lat: 37.787710, lng: -122.402879},
map: map,
labelContent: "A",
labelClass: "labels",
labelInBackground: false
});
// Add Ending Marker B
var markerB = new MarkerWithLabel({
position: {lat: 37.789440, lng: -122.401900},
map: map,
labelContent: "B",
labelClass: "labels",
labelInBackground: false
});
// Style the label
.labels {
font-weight: bold;
font-size: 16px;
color: #fff;
background-color: #333;
border-radius: 4px;
padding: 4px 8px;
text-align: center;
}
In this example, we're using the MarkerWithLabel
library to create markers with custom labels above them. We pass in the labelContent
parameter to set the text for the label, and the labelClass
parameter to style the label with CSS.
Note that you'll need to include the MarkerWithLabel
library in your project for this code to work. You can find more information on how to do that in the documentation for the library.
Asked: 2022-01-28 11:00:00 +0000
Seen: 12 times
Last updated: Oct 06 '22