Ask Your Question
1

How can I show a label above the starting marker A and ending marker B using the Google Maps JavaScript API?

asked 2022-01-28 11:00:00 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-10-06 20:00:00 +0000

david gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-01-28 11:00:00 +0000

Seen: 12 times

Last updated: Oct 06 '22