2

有人请为我修复此代码。我不能显示多个图钉 :( 或者给我一些关于显示图钉的链接。Ty :)

// Creat point
        GeoCoordinate p1 = new GeoCoordinate(21.0178, 105.8303);
        GeoCoordinate p2 = new GeoCoordinate(21.0076, 105.8414);
        // Show center map
        this.myPushpins.Center = p1;
        this.myPushpins.ZoomLevel = 13;
        // Creat Pushpins
        Pushpin pp = new Pushpin();
        // Creat MapOverLap
        MapOverlay overlay1 = new MapOverlay();
        overlay1.Content = pp;
        overlay1.GeoCoordinate = new GeoCoordinate(21.0178, 105.8303);
        MapOverlay overlay2 = new MapOverlay();
        overlay2.Content = pp;
        overlay2.GeoCoordinate = new GeoCoordinate(21.0076, 105.8414);
        // Creat Maplayer
        MapLayer layer = new MapLayer();
        layer.Add(overlay1);
        layer.Add(overlay2);
        myPushpins.Layers.Add(layer);
4

1 回答 1

3

您正在将两者的内容设置为overylay1overylay2一个Pushpin对象实例。您需要有两个不同的Pushpin. 试试这个代码:

    // Creat point
    GeoCoordinate p1 = new GeoCoordinate(21.0178, 105.8303);
    GeoCoordinate p2 = new GeoCoordinate(21.0076, 105.8414);
    // Show center map
    this.myPushpins.Center = p1;
    this.myPushpins.ZoomLevel = 13;
    // Creat Pushpins
    //Pushpin pp = new Pushpin();
    // Creat MapOverLap
    MapOverlay overlay1 = new MapOverlay();
    overlay1.Content = new Pushpin();
    overlay1.GeoCoordinate = new GeoCoordinate(21.0178, 105.8303);
    MapOverlay overlay2 = new MapOverlay();
    overlay2.Content = new Pushpin();
    overlay2.GeoCoordinate = new GeoCoordinate(21.0076, 105.8414);
    // Creat Maplayer
    MapLayer layer = new MapLayer();
    layer.Add(overlay1);
    layer.Add(overlay2);
    myPushpins.Layers.Add(layer);

或者更好的是有一些功能来显示你的别针

public void PinMap(Map map, GeoCoordinate geoPosition) {
    map.Center = geoPosition;
    map.ZoomLevel = 13;

    var mapOverlay = new MapOverlay();
    mapOverlay.Content = new Pushpin();
    mapOverlay.GeoCoordinate = geoPosition;

    var mapLayer = new MapLayer();
    mapLayer.Add(mapOverlay);

    map.Layers.Add(mapLayer);
}

PinMap(myMap, new GeoCoordinate(21.0178, 105.8303));
PinMap(myMap, new GeoCoordinate(21.0076, 105.8414));
于 2013-05-06T22:47:26.050 回答