我试图在我的应用程序的地图页面中绘制图钉到地图但是当我添加代码以将图钉覆盖到地图时,我收到以下错误:
找不到类型或命名空间名称
PushPin
(您是否缺少using指令或程序集引用?)
和
Microsoft.Phone.Maps.Controls.Map
不包含Children
的定义,并且没有可以找到接受类型Children
的第一个参数的扩展方法Microsoft.Phone.Maps.Controls.Map
我从中理解我错过了一个引用?我有controls.maps
和contols.toolkit
的参考资料,所以我无法理解原因。
这也是我用来绘制图钉的代码:
PushPin myPin = new Pushpin();
myPin.Location = MyGeoPosition;
myPin.Content = "My car";
MyMap.Children.Add(myPin);
答案 0 :(得分:2)
试试这个。
MapLayer layer1 = new MapLayer();
Pushpin pushpin1 = new Pushpin();
pushpin1.GeoCoordinate = MyGeoPosition;
pushpin1.Content = "My car";
MapOverlay overlay1 = new MapOverlay();
overlay1.Content = pushpin1;
overlay1.GeoCoordinate = MyGeoPosition;
layer1.Add(overlay1);
myMap.Layers.Add(layer1);
您可以为每个图钉创建新的叠加层,将所有叠加层添加到图层,然后将图层添加到地图元素中。
答案 1 :(得分:0)
你可以试试..
BitmapImage myImage1; myImage1 = new BitmapImage(new Uri("/Assets/Images/pushpin-google-hi.png", UriKind.RelativeOrAbsolute));
var image = new Image();
image.Width = 50;
image.Height = 50;
image.Opacity = 100;
image.Source = myImage1;
var mapOverlay = new MapOverlay();
mapOverlay.Content = image;
mapOverlay.GeoCoordinate = new GeoCoordinate(lats, lons);
var mapLayer = new MapLayer();
mapLayer.Add(mapOverlay);
MyMap.Layers.Add(mapLayer);
MyMap.SetView(new GeoCoordinate(lats, lons), 16);
答案 2 :(得分:0)
试试这个。首先,我在一个utils类中有这个:
public MapLayer GetCurrentPosition (out MapOverlay myPositionOverlay)
{
MapLayer myPositionLayer = new MapLayer();
myPositionOverlay = new MapOverlay();
Image myPositionImage = new Image();
myPositionImage.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("/Assets/myImagePin.png", UriKind.RelativeOrAbsolute));
myPositionImage.Height = 70;
myPositionImage.Visibility = Visibility.Visible;
myPositionImage.HorizontalAlignment = HorizontalAlignment.Center;
myPositionOverlay.Content = myPositionImage;
myPositionLayer.Add(myPositionOverlay);
return myPositionLayer;
}
然后这将继续你的MapLoaded方法:
MapLayer mypositionArrow = placePushPins.GetCurrentPosition(out myPositionOverlay);
MyMap.Layers.Add(mypositionArrow);
然后,如果你想要你的图钉不是静止的,要根据你的位置移动,把它添加到你的观察者:
myPositionOverlay.GeoCoordinate = myCurrentPositionCoordinate;
要使图钉平滑移动,只需执行以下动画:http://blogs.bing.com/maps/2014/09/25/part-2-bring-your-maps-to-life-creating-animations-with-bing-maps-net/