有人请为我修复此代码。我不能显示多个图钉:( 或者给我一些关于show pushpins的链接。 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);
答案 0 :(得分:3)
您正在将overylay1
和overylay2
的内容设置为相同的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));