none
Pushpin not always on the right location RRS feed

  • Question

  • I programmatically change the zoom with some map.SetView. The pushpin I centered before these calls are somehow navigating on the map but not always stop their course on the right location.

    I have tried to remove the pushpin and add it again but this does not resolve this problem.

    if (map.Children.Count > 0)

    { map.Children.Clear();}
    MapLayer.SetPosition(pushpin, _item.Center);
    map.Children.Add(pushpin);

    Yves


    Yves Pflieger

    Wednesday, May 9, 2012 8:38 AM

Answers

  • Are you setting the Anchor position? It defaults to top left of your pushpin which is not what you want for most things (including the default pushpin). Default pushpins will center properly in the next release but until then you need to set the center on them as such:

    MapLayer.SetPositionAnchor(pushpin, new Point(11, 11));

    For custom pushpins you'll want to specify your own anchor position.
    Wednesday, May 9, 2012 5:26 PM

All replies

  • Are you setting the Anchor position? It defaults to top left of your pushpin which is not what you want for most things (including the default pushpin). Default pushpins will center properly in the next release but until then you need to set the center on them as such:

    MapLayer.SetPositionAnchor(pushpin, new Point(11, 11));

    For custom pushpins you'll want to specify your own anchor position.
    Wednesday, May 9, 2012 5:26 PM
  • map.SetView(_item.Center, zoom, true); MapLayer.SetPosition(pushpin, _item.Center); MapLayer.SetPositionAnchor(pushpin, new Point(11, 11)); map.Children.Add(pushpin);

    I have added the SetPostionAnchor but the problem remains...

    Yves


    Yves Pflieger

    Monday, May 14, 2012 5:33 PM
  • Do you have a small repro for this that you can share?
    Monday, May 14, 2012 5:45 PM
  • I think the problems comes from the fact that I have two map control, one is set to Collapse. If i delete the second map control, the pushpin will be correctly placed. 
    Of course this code reproduce the bug, my true code is a bit more complex.
    
    Yves
    
           <Grid Background="{StaticResource ApplicationPageBackgroundBrush}">
                <bm:Map Name="map" MapType="Road" ZoomLevel="1"
                        Credentials="XXX" ShowScaleBar="False"
                        IsEnabled="True">
                </bm:Map>
                <bm:Map MapType="Road" ZoomLevel="1"
                        Credentials="XXX" ShowScaleBar="False"
                        IsEnabled="True" Visibility="Collapsed" />
           </Grid>
    
            protected override void OnNavigatedTo(NavigationEventArgs e)
            {
                int zoom = 6;
                Pushpin pushpin = new Pushpin();
                map.MapType = MapType.Road; 
                Location center = new Location(52.51638, 13.3785); // Set to Berlin, Germany
                map.SetView(center, zoom, true);
    
                MapLayer.SetPosition(pushpin, center);
                MapLayer.SetPositionAnchor(pushpin, new Point(11, 11));
                map.Children.Add(pushpin);
            }


    Yves Pflieger

    Monday, May 14, 2012 8:02 PM
  • Thanks. Yes it's because there are two maps. This will be fixed in the next public release of the map control.
    Monday, May 14, 2012 8:30 PM