• JavaScript
  • HTML
 * Creates a new marker and adds it to a group
 * @param {H.map.Group} group       The group holding the new marker
 * @param {H.geo.Point} coordinate  The location of the marker
 * @param {String} html             Data associated with the marker
function addMarkerToGroup(group, coordinate, html) {
  var marker = new H.map.Marker(coordinate);
  // add custom data to the marker

 * Add two markers showing the position of Liverpool and Manchester City football clubs.
 * Clicking on a marker opens an infobubble which holds HTML content related to the marker.
 * @param  {H.Map} map      A HERE Map instance within the application
function addInfoBubble(map) {
  var group = new H.map.Group();


  // add 'tap' event listener, that opens info bubble, to the group
  group.addEventListener('tap', function (evt) {
    // event target is the marker itself, group is a parent event target
    // for all objects that it contains
    var bubble =  new H.ui.InfoBubble(evt.target.getGeometry(), {
      // read custom data
      content: evt.target.getData()
    // show info bubble
  }, false);

  addMarkerToGroup(group, {lat:53.439, lng:-2.221},
City of Manchester Stadium
Capacity: 48,000
'); addMarkerToGroup(group, {lat:53.430, lng:-2.961}, '
Capacity: 45,362
'); } /** * Boilerplate map initialization code starts below: */ // initialize communication with the platform // In your own code, replace variable window.apikey with your own apikey var platform = new H.service.Platform({ apikey: window.apikey }); var defaultLayers = platform.createDefaultLayers(); // initialize a map - this map is centered over Europe var map = new H.Map(document.getElementById('map'), defaultLayers.vector.normal.map,{ center: {lat: 53.430, lng: -2.961}, zoom: 7, pixelRatio: window.devicePixelRatio || 1 }); // add a resize listener to make sure that the map occupies the whole container window.addEventListener('resize', () => map.getViewPort().resize()); // MapEvents enables the event system // Behavior implements default interactions for pan/zoom (also on mobile touch environments) var behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map)); // create default UI with layers provided by the platform var ui = H.ui.UI.createDefault(map, defaultLayers); // Now use the map as required... addInfoBubble(map);
<!DOCTYPE html>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=yes">
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
    <title>Opening an Infobubble on a Mouse Click</title>
    <link rel="stylesheet" type="text/css" href="https://js.api.here.com/v3/3.1/mapsjs-ui.css" />
    <link rel="stylesheet" type="text/css" href="demo.css" />
    <link rel="stylesheet" type="text/css" href="styles.css" />
    <link rel="stylesheet" type="text/css" href="../template.css" />
    <script type="text/javascript" src='../test-credentials.js'></script>    
    <script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-core.js"></script>
    <script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-service.js"></script>
    <script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-ui.js"></script>
    <script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-mapevents.js"></script>
  <script type="text/javascript" src='../js-examples-rendering-helpers/iframe-height.js'></script></head>
  <body id="markers-on-the-map">
    <div class="page-header">
        <h1>Opening an Infobubble on a Mouse Click</h1>
        <p>Open an infobubble when a marker is clicked</p>
    <p>This example displays a map with two markers showing the position 
      of <b>Liverpool</b> and <b>Manchester City</b> football clubs. Clicking on a 
      marker opens an infobubble which holds HTML content related to the marker.</p>
    <div id="map"></div>
    <p>Infobubble opens on <code>tap</code> event, event delegation is used to add event listener to the group that holds markers. 
      <code>setData/getData</code> methods on the map objects are used to bind custom data.</p>
    <script type="text/javascript" src='demo.js'></script>