how to show multiple pushpin to the radmap

7 posts, 0 answers
  1. Asiq Raja
    Asiq Raja avatar
    30 posts
    Member since:
    Jul 2010

    Posted 02 Feb 2011 Link to this post

    hi ,
         I m facing some pushpin binding problem.Let me explain the Flow of the Work.

    -  i m using wcf services to retrieve the Latitude and longitude,then
    -  i m using list object to get the list of latitude longitude.

    then i m using to following code to bind to the map control.
    // Code

    List<MeterContract> meterList = e.Result.ToList();
                ProvinceContract oPrvience;
                foreach (var item in meterList)
                {
                    oPrvience = new ProvinceContract();
                    oPrvience.Longitude = item.Longitude;
                    oPrvience.Latitude = item.Latitude;

                    if ((oPrvience.Latitude != string.Empty) && (oPrvience.Longitude != string.Empty))
                    {
                        // ******* This following code is used to show the pinpoint to the map.  *******
                        Location location = new Location(Convert.ToDouble(oPrvience.Latitude), Convert.ToDouble(oPrvience.Longitude));

                        MapPinPoint pinPoint = new MapPinPoint()
                        {
                            ImageSource = new BitmapImage(new Uri("../images/AreaPinpoint.png", UriKind.Relative))
                        };

                        MapLayer.SetLocation(pinPoint, location);

                        this.informationLayer.Items.Add(pinPoint);

                        this.radMap1.Center = location;
    }

    Note:

     But the only one  image is binding over the map. but i retrieve more then one latitude,longitude.
    so i m really confusing. and also i don't know how to do this, so plz do reply as soon as possible, its very urgent.

    and weather pushpin will support such a multiple options??.

    Do reply fast

    Thanks & regards
      M.Asiq Raja
  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 04 Feb 2011 Link to this post

    Hello Asiq Raja,

    Your code mostly looks OK. I’m not sure what are your MeterContract and ProvinceContract, so I can’t reproduce your code exactly. But it looks like these are objects which provide latitude and longitude as strings. So I’ve created my own class which simulates your MeterContract (it looks like ProvinceContract is not necessary in your code). You set the center of the RadMap to EVERY location from the list. It looks a bit strange. So I moved code from the loop to the end of the method and use first location form the list. The Convert.ToDouble method uses localization settings (number format) which are specific for your PC. If your WCF service returns data in a different format then your code will not work. So I’ve changed the way how the string is converted to double to use double.Parse and invariant culture settings. You also must be sure that your WCF service converts numbers to strings using invariant culture. Here it is my code:

    public class MeterContract
    {
        public string Latitude
        {
            get;
            set;
        }
      
        public string Longitude
        {
            get;
            set;
        }
    }
      
    public MainPage()
    {
        InitializeComponent();
      
        List<MeterContract> meterList = new List<MeterContract>();
        meterList.Add(new MeterContract() { Latitude = "42.5", Longitude = "-120" });
        meterList.Add(new MeterContract() { Latitude = "42", Longitude = "-120" });
        meterList.Add(new MeterContract() { Latitude = "41.5", Longitude = "-120" });
        meterList.Add(new MeterContract() { Latitude = "42.5", Longitude = "-110" });
        meterList.Add(new MeterContract() { Latitude = "42", Longitude = "-110" });
        meterList.Add(new MeterContract() { Latitude = "41.5", Longitude = "-110" });
        this.AddPinPointsFromList(meterList);
    }
      
    private void AddPinPointsFromList(List<MeterContract> meterList)
    {
        foreach (var item in meterList)
        {
            if (!string.IsNullOrEmpty(item.Latitude)
                && !string.IsNullOrEmpty(item.Longitude))
            {
                // ******* This following code is used to show the pinpoint to the map.  *******
                Location location = new Location(
                    double.Parse(item.Latitude, System.Globalization.CultureInfo.InvariantCulture),
                    double.Parse(item.Longitude, System.Globalization.CultureInfo.InvariantCulture));
      
                MapPinPoint pinPoint = new MapPinPoint()
                {
                    ImageSource = new BitmapImage(new Uri("../images/AreaPinpoint.png", UriKind.Relative))
                };
      
                MapLayer.SetLocation(pinPoint, location);
      
                this.informationLayer.Items.Add(pinPoint);
            }
        }
      
        Location center = new Location(
            double.Parse(meterList[0].Latitude, System.Globalization.CultureInfo.InvariantCulture),
            double.Parse(meterList[0].Longitude, System.Globalization.CultureInfo.InvariantCulture));
      
        this.radMap.Center = center;
    }

    Using a modified code I can see all 6 pin points on the map. I suppose that the problem is in the values are returned by your WCF service.

    All the best,
    Andrey Murzov
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  3. DevCraft banner
  4. Asiq Raja
    Asiq Raja avatar
    30 posts
    Member since:
    Jul 2010

    Posted 04 Feb 2011 Link to this post

    Hi Andrey Murzov,

           Thanks for the reply its really helpful,  and also i finished that task my self, and Thanks again for your valuable support.

    Thanks & regards
     M.Aisq Raja
  5. Zi
    Zi avatar
    13 posts
    Member since:
    Jun 2013

    Posted 25 Jun 2013 Link to this post

    I am doing a campus floor plan, and I use the telerik for WPF control.Since I am very new to it. Could I ask you to look at my project for a seconds?

    private void MRT_touchdown(object sender, TouchEventArgs e)
            {
                List<MeterContract> meterList = new List<MeterContract>();
                meterList.Add(new MeterContract() { Latitude = "1.38115", Longitude = "103.84536" });
                this.AddPinPointsFromList(meterList);

            }
      private void AddPinPointsFromList(List<MeterContract> meterList)
            {
                foreach (var item in meterList)
                {
                    if (!string.IsNullOrEmpty(item.Latitude)
                        && !string.IsNullOrEmpty(item.Longitude))
                    {
                        // ******* This following code is used to show the pinpoint to the map.  *******
                        Location location = new Location(
                            double.Parse(item.Latitude, System.Globalization.CultureInfo.InvariantCulture),
                            double.Parse(item.Longitude, System.Globalization.CultureInfo.InvariantCulture));

                        MapPinPoint pinPoint = new MapPinPoint()
                        {
                            ImageSource = new BitmapImage(new Uri("/bus.png", UriKind.Relative))
                        };

                       
                    }
                }

                Location center = new Location(
                 double.Parse(meterList[0].Latitude, System.Globalization.CultureInfo.InvariantCulture),
                 double.Parse(meterList[0].Longitude, System.Globalization.CultureInfo.InvariantCulture));

                this.radMap.Center = center;
            }
    I follow your answer to do my project..but Can;t show the pinpoint in the map..actually the centre can be moved, but no pinpoint shown.

  6. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 27 Jun 2013 Link to this post

    Hi Zi,

    As I can see from your code the MapPinPoint has been created, but you have not specified the location for it. The location can be specified via the MapLayer.Location attachable property using the MapLayer.SetLocation method in a code-behind. Also you should add the MapPinPoint to the information layer to show it on the map the same way as in the previous post.
    MapPinPoint pinPoint = new MapPinPoint()
    {
        ImageSource = new BitmapImage(new Uri("../images/AreaPinpoint.png", UriKind.Relative))
    };
     
    MapLayer.SetLocation(pinPoint, location);
     
    this.informationLayer.Items.Add(pinPoint);

    For more details I would recommend to take a look at the following documentation topics:
    http://www.telerik.com/help/wpf/radmap-features-information-layer.html
    http://www.telerik.com/help/wpf/radmap-features-information-layer-pin-points.html

    Regards,
    Andrey Murzov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  7. Zi
    Zi avatar
    13 posts
    Member since:
    Jun 2013

    Posted 27 Jun 2013 Link to this post

    hi, Andrey

    Thank you very  much. That problem I already solved because the image path must use the full path for it.
    However, Now I got a big problem.
    For my project, I want to show 2 functions.  
    one of it is touchdown the part of map, which can show the detail information(image). The second one is use the button"touch down " to show some general palce collection(car park). Now I am complete the second function.

    According to the first one, I am consider to use the  "InformationLayer and InitializedCompleted" which is I learn in the RadControl document, and add the ellipse on the map for touch to show detail information.
    I create the data template with the ellipse on the RadMap, a MapItem.cs and add the InitializedCompleted event. If I only to show this function, the Ellipse can show on the map. But, Later I add  the button"touch down" to call another method to show pinpoint such as the carpark on the map. Just like you said
     MapLayer.SetLocation(pinPoint, location);

                        this.informationLayer.Items.Add(pinPoint);
    After all that, I got this problem "error: Invaliad operation Exception was unhandled.
    Items collection must be empty before using ItemsSource." in the line  "void radMap_InitializeCompleted(object sender, EventArgs e)
            {
            this.informationLayer.ItemsSource = this.GetMapData();
            }"

    I am thinking that  whether the imformationLayer can't add the item twice?
    Or you got a goog idear to show the first "touch down" on the map function?
    Looking forwards to your reply, thank you very much.

  8. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 28 Jun 2013 Link to this post

    Hi Zi,

    This is a standard behaviour of any ItemsControl (the InformationLayer inherits the ItemsControl). You can't use ItemsSource and Items collection at the same time. You can find more information about it in the MSDN.
    Just out of the curiosity, why don't you use the same approach (ItemsSource or Items collection) to add items in both cases?
    You can find how the items of different types can be used on the same InformationLayer here:
    http://demos.telerik.com/silverlight/#Map/DataBinding

    Regards,
    Andrey Murzov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top
DevCraft banner