如何将图钉项添加到地图吗? Windows手机 [英] How to add a PushPin item to a map? Windows Phone
问题描述
我想画一个图钉在我的应用程序的地图页面的映射,但是当我添加代码来覆盖一个图钉的地图,我收到以下错误:
类型或命名空间名称
图钉
找不到(是否缺少using指令或程序集引用?)
块引用>
和
Microsoft.Phone.Maps.Controls.Map
不包含儿童的定义
并没有扩展方法孩子
接受一个类型的第一个参数Microsoft.Phone.Maps.Controls.Map
可寻
块引用>
据我所知从这个是我缺少一个参考?我有引用
controls.maps
和contols.toolkit
,所以我不明白为什么。
另外这是我使用绘制图钉的代码:
图钉myPin =新图钉();
myPin.Location = MyGeoPosition;
myPin.Content =我的车;
MyMap.Children.Add(myPin);
解决方案试试这个。
MapLayer层1 =新MapLayer();
图钉pushpin1 =新图钉();
pushpin1.GeoCoordinate = MyGeoPosition;
pushpin1.Content =我的车;
MapOverlay overlay1 =新MapOverlay();
overlay1.Content = pushpin1;
overlay1.GeoCoordinate = MyGeoPosition;
layer1.Add(overlay1);
myMap.Layers.Add(层);
您为每个图钉创造新的覆盖,添加所有覆盖到层,层添加到地图元素。
I'm trying to draw a pushpin to a map in the map page of my application but when I add the code to overlay a pushpin to the map, I get the following errors:
The type or namespace name
PushPin
could not be found (are you missing a using directive or an assembly reference?)and
Microsoft.Phone.Maps.Controls.Map
does not contain a definition forChildren
and no extension methodChildren
accepting a first argument of typeMicrosoft.Phone.Maps.Controls.Map
could be foundI understand from this that I'm missing a reference? I have references for
controls.maps
andcontols.toolkit
, so I can't understand why.Also this is the code I'm using to draw the pushpin:
PushPin myPin = new Pushpin(); myPin.Location = MyGeoPosition; myPin.Content = "My car"; MyMap.Children.Add(myPin);
解决方案Try this.
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);
You create new overlay for each pushpin, add all overlays to a layer, and add the layer to the map element.
这篇关于如何将图钉项添加到地图吗? Windows手机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!