Answered PushPin Tap Event Null Reference Exception

  • Sunday, August 19, 2012 11:57 PM
     
      Has Code
    void tappy(object sender, GestureEventArgs e)
        {
            ApplicationBar.IsVisible = true;
            var pp = sender as Pushpin;
            MessageBox.Show(map1.Children.IndexOf(pp).ToString());
            MessageBox.Show(pp.Location.Latitude.ToString() + ", " + pp.Location.Longitude.ToString());
        }

    After setting multiple pushpins on the Bing Map, I want to show information about the pin when the user tap on it. I tried to code about and the output of the first messagebox is "-1" and the second one throws an "null reference exception".

    I used JSON deserialization and created fields for storing data gathered from google maps. Coud the usage of JSON(since asynchronous) be the source of my problem? If not, what else could cause this exception to be thrown?

All Replies

  • Monday, August 20, 2012 10:00 AM
    Owner
     
     

    A couple of questions to start off with. Are you using the WPF or the Silverlight control? Is the pushpins added as children of the map or as children of a MapLayer? JSON deserialization is likely not your issue. You may need to cast the sender as a Pushpin rather than using the "as" keyword.

    Also, note that mixing in data from Google Maps with Bing Maps is against the terms of use for both Google and Bing Maps.


    http://rbrundritt.wordpress.com

  • Monday, August 20, 2012 11:42 AM
     
      Has Code
                GeoCoordinate mapCener = new GeoCoordinate(39.920794, 32.853902);
                Pushpin pin1 = new Pushpin();
                pin1.Location = mapCener;
                pin1.Template = (ControlTemplate)(this.Resources["hereTemplate"]);     
                map1.Children.Add(pin1);
                int zoom = 14;
                map1.SetView(mapCener, zoom);    

    Here is the code that I used for creating pushpins displaying them on the map. I will choose bing maps or google maps at the end of my project.
  • Monday, August 20, 2012 2:14 PM
    Owner
     
     
    Ok, you still haven't answered my main questions. Is this a Silverlight, WPF or WP7 app? Also, there doesn't appear to be any touch or click event attached to the pushpin in your code. Also note that Google Maps tiles cannot be used in the Bing Maps WP7 control.

    http://rbrundritt.wordpress.com

  • Monday, August 20, 2012 3:01 PM
     
     
    Ok, you still haven't answered my main questions. Is this a Silverlight, WPF or WP7 app? Also, there doesn't appear to be any touch or click event attached to the pushpin in your code. Also note that Google Maps tiles cannot be used in the Bing Maps WP7 control.

    http://rbrundritt.wordpress.com

    I forgot it... It's a WP7 application.
  • Tuesday, August 21, 2012 2:21 PM
     
     
    Ok, you still haven't answered my main questions. Is this a Silverlight, WPF or WP7 app? Also, there doesn't appear to be any touch or click event attached to the pushpin in your code. Also note that Google Maps tiles cannot be used in the Bing Maps WP7 control.

    http://rbrundritt.wordpress.com

    The "tappy" is a tap event itself. I use google places A PI + JSON and generate a list of "coordinates" and then display them as pushpins on Bing Maps. 

    Question: How to get the coordinates of the pushpin back from the bing maps by using "tap event".
  • Tuesday, August 21, 2012 2:49 PM
    Owner
     
     Answered

    It is against the terms of use of both Bing Maps and Google Maps to mix data between the platforms. Showing coordinates from Google Places API on Bing Maps is not allowed.


    http://rbrundritt.wordpress.com