What happens to my second pushpin? It does not appear on the map. The first one does, but that the only one.

DaPaul 26 Reputation points
2021-04-12T13:01:06.933+00:00

I have tried this demo:

var map = new Microsoft.Maps.Map(document.getElementById('myMap'), {
center: new Microsoft.Maps.Location(47.60995, -122.34009)
});
Microsoft.Maps.loadModule('Microsoft.Maps.WellKnownText', function () {
// Add a Pushpin at Seattle
map.entities.push(Microsoft.Maps.WellKnownText.read('POINT(-122.34009 47.60995)'));
});

Works fine. But if I try to add another PushPin by adding the following lines to the above program, like this:

Microsoft.Maps.loadModule('Microsoft.Maps.WellKnownText', function () {
// Add a Pushpin somewhere
map.entities.push(Microsoft.Maps.WellKnownText.read('POINT(-122.35009 47.61995)'));
});

another PushPin should appear. But it doesn't.

Hope someone can give me some advice, I cannot see why it doesn't work.

Thanks and best regards

PoulK

Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
696 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. rbrundritt 17,181 Reputation points Microsoft Employee
    2021-04-12T18:48:31.813+00:00

    A couple of things to look into to.

    1. Try zooming the map in. Those two coordinates are less than a mile apart, which means at around zoom level 7 the two coordinates would be rendered in the exact same pixel location and overlapping. When you zoom in closer the pin icons would likely still overlap a bit, until you are zoomed in to about city level.
    2. Generally you only need to load a module once. Loading the module repeatedly just complicates the code and adds more code for you to debug.
    3. Make sure you don't have any other code that runs that clears the map between these two calls. Note that loading a module is asynchronous, so a clear method could be called further down in your code but be processed before the module load callback is called.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.