2

I haven’t been able to find documentation on it - Is it possible to have a marker always be centered on the map - have the map be moveable but the marker always in the center of it?

Any help is greatly appreciated!

Update - here is the JS we're currently using:

<script src="https://js.api.here.com/v3/3.0/mapsjs-core.js" type="text/javascript" charset="utf-8"></script>
<script src="https://js.api.here.com/v3/3.0/mapsjs-service.js" type="text/javascript" charset="utf-8"></script>
<script src="https://js.api.here.com/v3/3.0/mapsjs-ui.js" type="text/javascript" charset="utf-8"></script>
<script src="https://js.api.here.com/v3/3.0/mapsjs-mapevents.js" type="text/javascript" charset="utf-8"></script>
CustardBun
  • 3,457
  • 8
  • 39
  • 65

1 Answers1

2

You can register a 'sync' event listener and then retrieve the center of the map any time the map view changes. You can then set the position of your marker to the retrieved center coordinates. See code snippet:

map.getViewModel().addEventListener('sync', function() {
  var center = map.getCenter();
  // Set marker position here:
  // <marker object>.setPosition(center);
});
  • It seems that in this case, while the customer is dragging the map, the pin will stay the existing location until they release. Is there any way to keep it so that the pin is never *not* in the center? – CustardBun May 28 '19 at 19:24
  • If you try the code you will see that the pin (marker) is always in the center since the sync event is triggered on every move event and not only when the event is done. –  May 29 '19 at 06:12
  • I did, and it looks pretty good with the pin staying somewhat centered. However, if you move the map really fast it's not always in sync. If there's a way to make the marker actually never visibly move, that would be even better, but this helps. – CustardBun May 30 '19 at 18:21