Search code examples
windows-phone-8.1bing-mapspushpingeopositioning

How to add a dynamic PushPin to map in WP8.1


I'm currently trying to develop an simple application that allows user to add new pushpins. I'm currently using following code to add new pushpins,

        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);

But, to use this code, I need the latitude and longitude of the location that user has selected. So how can I get the latitude and longitude of the location that user has selected. (Simply geo-coordinate) I know I need to write a event handler, But I don't know the way that it has to be implemented... Thank you...


Solution

  • Try This

    MapA = new Map();
    MapA.Tap += MapA_Tap;
    
    void MapA_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
             GeoCoordinate location = MapA.ConvertViewportPointToGeoCoordinate(e.GetPosition(MapA));
    
     //display pushpin by using location.latitude and location.longitude
    }