问题
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