Reputation: 1384
I'm trying to add a Pushpin to my MapControl on Tap. The problem I am facing is, the GestureEventArgs passes a Map relative co-ordinate for eg:
X = 216
Y = 197
Due to this I am not able to assign the Co-ods on a Pushpin to Add into the map. Here's exactly what I am doing.
private void MainMap_Tap(object sender, GestureEventArgs e)
{
Point p = e.GetPosition(this.MainMap);
GeoCoordinate g = new GeoCoordinate();
g = MainMap.ViewportPointToLocation(p);
MyPin.Location = g;
MainMap.Children.Add(MyPin);
}
My code breaks due to a Null Reference Error at MyPin.Location = g. In g I get values like
g = {-0.00446319579627641, 0.00369071960449219}
Upvotes: 0
Views: 182
Reputation: 15006
Probably because your MyPin is not initialized.
You cannot set the Location of a Pushpin if it's null.
http://msdn.microsoft.com/en-us/library/gg588563(v=vs.92)
Upvotes: 2