This is a migrated thread and some comments may be shown as answers.

Map doesn't show ...

4 Answers 102 Views
Map
This is a migrated thread and some comments may be shown as answers.
Kamal Mostofi
Top achievements
Rank 1
Kamal Mostofi asked on 10 Apr 2011, 10:19 AM

Hi,
I followed the example in Telerik demo to search for a location. this is the code behind

#if SILVERLIGHT
        private string VEKey = "AgWnkUbvO_qS8-uaGDqbJPTTb84q1iDP1If_CHqwPz91-...........";
#endif
        private MapItemsCollections itemCollection = new MapItemsCollections();
  
        private BingSearchProvider searchProvider;
         
        public ViewProperties()
        {
            InitializeComponent();
            this.landpropertyDomainDataSource.QueryParameters.Add(new Parameter { ParameterName = "propertyid", Value = 4 });
            this.landpropertyDomainDataSource.Load();
            //this.radMap.Provider = new BingMapProvider(MapMode.Aerial, true, "AgWnkUbvO_qS8-uaGDqbJPTTb84q1iDP1If_CHqwPz91-............");
            //this.searchProvider = new BingSearchProvider();
            //searchProvider.ApplicationId = "AgWnkUbvO_qS8-uaGDqbJPTTb84q1iDP1If_CHqwPz91-.............
            //searchProvider.MapControl = this.radMap;
  
#if SILVERLIGHT
            this.GetVEServiceKey();
#else
            this.SetProvider();
#endif
  
            //SearchRequest request = new SearchRequest();
            //request.Query = "W13 0GH";
            //this.searchProvider.SearchAsync(request);
            //searchProvider.SearchCompleted += this.searchProvider_SearchCompleted;
        }
  
        // Initialize Virtual Earth map provider.
        private void SetProvider()
        {
#if SILVERLIGHT
            BingMapProvider provider = new BingMapProvider(MapMode.Aerial, true, this.VEKey);
#else
            BingMapProvider provider = new BingMapProvider(MapMode.Aerial, true, BingMapHelper.VEKey);
            provider.IsTileCachingEnabled = true;
#endif
            this.radMap.Provider = provider;
  
            // Init searh provider.
            searchProvider = new BingSearchProvider();
#if SILVERLIGHT
            searchProvider.ApplicationId = this.VEKey;
#else
            searchProvider.ApplicationId = BingMapHelper.VEKey;
#endif
            searchProvider.MapControl = this.radMap;
  
            searchProvider.SearchCompleted += new EventHandler<SearchCompletedEventArgs>(Provider_SearchCompleted);
            SearchHandler();
        }
  
#if SILVERLIGHT
        private void GetVEServiceKey()
        {
            WebClient wc = new WebClient();
            wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
            //Uri keyURI = new Uri(URIHelper.CurrentApplicationURL, VEKey);
            //wc.DownloadStringAsync(keyURI);
        }
  
        void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
        //  this.VEKey = e.Result;
            this.SetProvider();
        }
#endif
  
        private void SearchHandler()
        {
            string query = "W5 2BP";
  
            if (!string.IsNullOrEmpty(query))
            {
                SearchRequest request = new SearchRequest();
                //request.Culture = new System.Globalization.CultureInfo("en-GB");
                request.Query = query;
  
                this.searchProvider.SearchAsync(request);
            }
        }
  
        private void Provider_SearchCompleted(object sender, SearchCompletedEventArgs args)
        {
            SearchResponse response = args.Response;
  
            if (response != null && response.ResultSets.Count > 0)
            {
                if (response.ResultSets[0].Results.Count > 0)
                {
                    this.itemCollection.Clear();
                    foreach (SearchResultBase result in response.ResultSets[0].Results)
                    {
                        MyMapItem item = new MyMapItem()
                        {
                            Title = result.Name,
                            Location = result.LocationData.Locations[0]
                        };
                        this.itemCollection.Add(item);
                    }
                }
  
                if (response.ResultSets[0].SearchRegion != null)
                {
                    // Set map viewport to the best view returned in the search result.
                    this.radMap.SetView(response.ResultSets[0].SearchRegion.GeocodeLocation.BestView);
  
                    // Show map shape around bounding area
                    if (response.ResultSets[0].SearchRegion.BoundingArea != null)
                    {
                        MapShape boundingArea = response.ResultSets[0].SearchRegion.BoundingArea;
                        boundingArea.Stroke = new SolidColorBrush(Colors.Red);
                        boundingArea.StrokeThickness = 1;
                        this.informationLayer2.Items.Add(boundingArea);
                    }
  
                    if (response.ResultSets[0].SearchRegion.GeocodeLocation.Address != null
                        && response.ResultSets[0].SearchRegion.GeocodeLocation.Locations.Count > 0)
                    {
                        foreach (Location location in response.ResultSets[0].SearchRegion.GeocodeLocation.Locations)
                        {
                            MyMapItem item = new MyMapItem()
                            {
                                Title = response.ResultSets[0].SearchRegion.GeocodeLocation.Address.FormattedAddress,
                                Location = location
                            };
                            this.itemCollection.Add(item);
                        }
                    }
                }
            }
        }

and here is the other classes i added to the SL app

using System;
using System.Collections.ObjectModel;
  
  
namespace BijansHome.Map.Search
{
    public class MapItemsCollections : ObservableCollection<MyMapItem>
    {
    }
}
  
using System;
using Telerik.Windows.Controls.Map;
  
  
namespace BijansHome.Map.Search
{
    public class MyMapItem
    {
        public Location Location
        {
            get;
            set;
        }
  
        public string Title
        {
            get;
            set;
        }
  
        public string Description
        {
            get;
            set;
        }
    }
}

Can you tell me where I do wrong in the code?

Thanks,
Kam

4 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 13 Apr 2011, 08:09 AM
Hello Kamal Mostofi,

It is very complicated to reproduce the problem using just a code snippet. But it seems that you did not bind the item collection to the information layer. The constructor of your class should contain a code like to the following:
this.informationLayer.DataMappings.Add(
    new DataMapping("Location", DataMember.Location));

Binding binding =
new Binding();
binding.Source = this.itemCollection;
this.informationLayer.SetBinding(ItemsControl.ItemsSourceProperty, binding);

All the best,
Andrey Murzov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Kamal Mostofi
Top achievements
Rank 1
answered on 16 Apr 2011, 11:13 AM
Hello, thanks for your response. Do you have an example for getting data from database (postcode or a city) and display it on the map? I followed the "Search" example but I can't make it work! URIHelper is missing.
I am new to Map control! :-(
Thanks for your help.
Kam
0
Kamal Mostofi
Top achievements
Rank 1
answered on 16 Apr 2011, 11:44 AM
Hi,
I was able to make it work withough URIHelper but to get the data displayed, I should add the method to a button. I would like to display the location on pageload!
Any idea?

And also could you tell me how I can add a Pin to the location?

Thanks,
kam
0
Andrey
Telerik team
answered on 20 Apr 2011, 12:06 PM
Hello Kamal Mostofi,

You've started from quite complex example. I would recommend you to start from very basic things and study some concepts. Here are a few links in our demo application and documentation to start:

http://www.telerik.com/help/silverlight/radmap-getting-started.html
http://www.telerik.com/help/silverlight/radmap-features-information-layer-framework-elements.html
http://www.telerik.com/help/silverlight/radmap-features-data-binding.html

Please, read these topics carefully and try to implement code snippets are provided in these topics. It will give you better understanding of how different things work in the RadMap.

All the best,
Andrey Murzov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Map
Asked by
Kamal Mostofi
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Kamal Mostofi
Top achievements
Rank 1
Share this question
or