How to convert GeoCoordinate to Pushpin Location in C#?

80 Views Asked by At

I'm trying to make a pushpin for my current location, the examples I could find online all give me the same error of "Cannot implicitly convert type 'System.Device.Location.GeoCoordinate' to 'Microsoft.Maps.MapControl.WPF.Location'.

Here is the code segment;

            GeoCoordinateWatcher watcher = new GeoCoordinateWatcher();
            GeoCoordinate looc = watcher.Position.Location;
            Pushpin piin = new Pushpin();
            piin.Location = looc; //error here

I'm using XAML and Bing maps if that makes a difference.

1

There are 1 best solutions below

0
Duncan Lawler On

You will need to create a new Location object for the pushpin, populating it with the latitude/longitude of the GeoCoordinate object. Note that the WPF control is old and no longer updated. If you're developing a new application it's recommended to use the UWP map control which can handle GeoCoordinate directly.