如何将图钉项添加到地图吗? Windows手机 [英] How to add a PushPin item to a map? Windows Phone

查看:253
本文介绍了如何将图钉项添加到地图吗? Windows手机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想画一个图钉在我的应用程序的地图页面的映射,但是当我添加代码来覆盖一个图钉的地图,我收到以下错误:




类型或命名空间名称图钉找不到(是否缺少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 for Children and no extension method Children accepting a first argument of type Microsoft.Phone.Maps.Controls.Map could be found

I understand from this that I'm missing a reference? I have references for controls.maps and contols.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆