Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phone 7 Bing map control - Add a pushpin when tap

I am using the latest Phone 7 RTM tools ( downloaded it today, October 7 2010).

I am trying to do a simple thing here:

when the user taps once on the map control, i want to put a pushpin there. also, i want to keep the regular built-in behavior of the map control ( tap twice to zoom).

(If it's not possible to keep both behaviors , then maybe a long press on the map to put pushpin).

When trying figuring this out, i came across this documentation of the changes made to the control map for Phone7: http://msdn.microsoft.com/en-us/library/ff955762.aspx

Then i saw the new class MapInputEventArgs, which has a ViewportPoint member.

When looking at code examples on the regular SilverLight map control i saw something like this:

private void OnMouseClick(object sender, MapMouseEventArgs e)
    {
        Point clickLocation = e.ViewportPoint;
        Location location = x_Map.ViewportPointToLocation(clickLocation);

        Pushpin pushpin = new Pushpin(); 
        m_PushpinLayer.AddChild(pushpin, new Location(latitude, longitude));
    }

But in Phone7 case, I can't find the appropriate event handler, and I could not find who uses MapInputEventArgs in the map control. Searching it on google gets me only 1 result !!

So , where is the appropriate event for "Tap once", and how can i get a ViewportPoint after this event has been fired ?

Thanks in advance.

like image 781
Yaron Levi Avatar asked Oct 07 '10 09:10

Yaron Levi


2 Answers

Just figured this out if you are still having problems.

The MouseLeftButtonUp and MouseLeftButtonDown Events have a GetPosition Method that will return the point your looking for

 private void MapMain_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {

        Point p = e.GetPosition(this.MapMain);
        GeoCoordinate geo = new GeoCoordinate();
        geo = MapMain.ViewportPointToLocation(p);
        MapMain.ZoomLevel = 17;
        MapMain.Center = geo;
        //---create a new pushpin---
        Pushpin pin = new Pushpin();

        //---set the location for the pushpin---
        pin.Location = geo;

        //---add the pushpin to the map---
        MapMain.Children.Add(pin);
    }
like image 110
Glen Colby Avatar answered Sep 21 '22 18:09

Glen Colby


Unless I'm reading your question wrong, this seems to be exactly what you're looking for:

Silverlight - Add Pushpin to Bing Maps via C#

like image 33
CACuzcatlan Avatar answered Sep 23 '22 18:09

CACuzcatlan