Search code examples
windows-phone-7cloudbing-mapspins

How can I allow the user to drop several seperate pins on bing map wp7?


I would like the user to add several pins to a map to represent tents or people using map1_Hold event. How can I do this and store each dropped pin location on a cloud later(windows azure)?


Solution

  • To drop pins on a map you can do the following: (here map comes from my .xaml page where map is the name of the Map: <my:Map Name="map" ...

    Setting up the event handler

    map.Hold += new EventHandler<GestureEventArgs>(dropPin_Hold);
    

    and the actual event handler:

    void dropPin_Hold(object sender, GestureEventArgs e)
    {
        // drop a pin at the Held location
        GeoCoordinate pinLocation = new GeoCoordinate();
        // gets the dropped position
        pinLocation = map.ViewportPointToLocation(e.GetPosition(map));
    
        newLocation = new Pushpin() { Location = pinLocation, Name = "Tent's name" Content = "new tent" };
        map.Children.Add(newLocation);
    
        // save the newLocation however you want
    
    }
    

    Multiple holds will result in multiple pins being displayed on the map.

    You might also want to check out map.Tap