답변됨 PushPin Tap Event Null Reference Exception

  • 2012년 8월 19일 일요일 오후 11:57
     
      코드 있음
    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?

모든 응답

  • 2012년 8월 20일 월요일 오전 10:00
    소유자
     
     

    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

  • 2012년 8월 20일 월요일 오전 11:42
     
      코드 있음
                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.
  • 2012년 8월 20일 월요일 오후 2:14
    소유자
     
     
    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

  • 2012년 8월 20일 월요일 오후 3:01
     
     
    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.
  • 2012년 8월 21일 화요일 오후 2:21
     
     
    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".
  • 2012년 8월 21일 화요일 오후 2:49
    소유자
     
     답변됨

    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