I am working on a Windows Phone 7 app that displays SF MUNI stops and times. I already published it, but want to add map functionality. So, I added a map, on which is displayed stops (inbound or outbound) for a specific user picked route. Here is the code I have for that, which works and displays each stop on a route:
//coords is an array of GeoCoordinates for each stop
//limit is the number of stops
GeoCoordinate [] coords=new GeoCoordinate[limit];
//pin is an array of Pushpins for each stop to add to the map
Pushpin[] pin = new Pushpin[limit];
for (int i = 0; i < limit; i++)
{
pin[i] = new Pushpin();
}
for (int i = 0; i < limit; i++)
{
coords[i] = new GeoCoordinate(Convert.ToDouble(latitude[inb[i]]), Convert.ToDouble(longitude[inb[i]]));//populate coords array
pin[i].Location = coords[i];//assign coords to pushpin location for each stop
}
//wires up event handler for clicking on each stop
for (int i = 0; i < limit; i++)
{
pin[i].MouseLeftButtonUp += new MouseButtonEventHandler(pin_MouseLeftButtonUp);
}
//Adds a pin at each stop's geocoords for each station
for (int i = 0; i < limit; i++)
map1.Children.Add(pin[i]);
So, the above code does place pushpins at each geocoordinate correctly. What I am totally stumped at, is how, if I press a pushpin, do I get the geocoordinate for that pushpin? In other words, when I press a pushpin, I want to capture pin[i].Location (which is a GeoCoordinate) in some sorta variable.
thanks, I hope this explains my problem.
Amanda
You should use the
Tapevent instead ofMouseLeftButtonUp. (and make sure to remove it when leaving the page!) and you can put a reference to theGeoCoordinateinpin[i].Tag.Tagis a grab bag reference to whatever you want — in your case, you want to put aGeoCoordinate, but you can put whatever you want — and it exists on allUIElements.In your
Tapevent listener, you can get a reference to yourGeoCoordinatelike: