Windows Phone 7 - Map PushPin not moving with the map?

∥☆過路亽.° 提交于 2019-12-14 03:09:44

问题


Bit of a weird one. I've recently started WP7 development and trying to port over an iOS app I have written. One part of the application involves placing a pin on a map using a latitude and longitude. I have this working fine using:

  Pushpin pushpin = new Pushpin();
  Location location = new Location();
  location.Latitude = lat;
  location.Longitude = lng;
  pushpin.Location = location;
  pushpin.Name = name;
  MyMap.Children.Add(pushpin);

The pin appears fine, however when I drag the map or Zoom, the pin stays at the centre point of the screen and not in its location relevant to the map. So if the user drags the map left, the pin stays in it's position at the centre of the screen rather than sticking to it's coordinate on the map.

Is there something I need to be setting but I am currently missing? Thanks for any help


回答1:


It looks to me like you might benefit from making use of the GeoCoordinate class and a ViewModel to bind your location data to application controls.

A few samples have just been published that should be able to help you. The Geo-Location iPhone to Windows Phone migration sample (http://windowsphone.interoperabilitybridges.com/articles/iphone-to-windows-phone-geo-location) is directly applicable to your situation. You can download both the iOS and Windows Phone samples via links at the bottom of the article.




回答2:


Your specified location is invalid. If it's not a valid GeoCoordinate, it'll stay fixed in the middle of the screen.

I'm not sure why you're using a Location since that's the Silverlight class, not the Windows Phone class, for the Pushpin. Are you certain you're adding the right references and using the right pushpin type?

Your code shouldn't even compile, if you used the right assembly for Bing Maps, which are the Microsoft.Phone.Controls.Maps assembly.

See http://msdn.microsoft.com/en-us/gg266447 for a good tutorial about how to use pushpins.



来源:https://stackoverflow.com/questions/7679979/windows-phone-7-map-pushpin-not-moving-with-the-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!