有人请为我修复这个代码。我不能显示多个图钉:(或者给我一些关于展示图钉的链接。泰:)
// 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);
将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));