Question

I'm using C# to create a windows store app using bing maps. I am trying to store and retrieve the location of a randomly placed pushpin on a map but when I use pushpin.Location for trying to print the location for example, I get the following error:

'Bing.Maps.Pushpin' does not contain a definition for 'Location' and no extension method 'Location' accepting a first argument of type 'Bing.Maps.Pushpin' could be found (are you missing a using directive or an assembly reference?)

The simple code example below show what I mean a bit more clearly:

private async void pushpinTapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
{
      MessageDialog dialog = new MessageDialog("You are here" + pushPin.Location());
      await dialog.ShowAsync();
}

It states clearly that location is a property of the the pushpin class in the API here There's also examples of it being used for windows phone 7, like in this question.

Any ideas what I'm missing? or is this functionality not available for Windows 8?

Was it helpful?

Solution

It works like:

async void pin_Tapped(object sender, TappedRoutedEventArgs e)
        {
            Pushpin pin = sender as Pushpin;
            Location pinLocation = MapLayer.GetPosition(pin);
            MessageDialog dialog = new MessageDialog("You are here: " + pinLocation.Latitude +", " + pinLocation.Longitude);
            await dialog.ShowAsync();
        }

OTHER TIPS

Ah nice one thank you. I found another way to do it too. Essentially the same thing but using var x instead of Location.

private async void pushpinTapped(object sender,Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
{
     Pushpin tappedpin = sender as Pushpin;  
     if (null == tappedpin) return;  
     var x = MapLayer.GetPosition(tappedpin); 
     MessageDialog dialog = new MessageDialog("You are here " + x.Latitude + ", " + x.Longitude);
     await dialog.ShowAsync();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top