Pushpins on map

Apr 5, 2010 at 4:39 PM
Edited Apr 5, 2010 at 5:13 PM

I have an xml file with list of cities with their latitude and longitudes(Color needs to be decided based on a different xml file). How do i plot those as pushpins on the map? Also, when a city pushpin is clicked, i want to show the pushpins of all the stores in that city. Please help

Coordinator
Apr 6, 2010 at 9:39 PM

In the latest source code version there is a project called DataBindingSample that shows how to bind pushpins to a data source. You can adapt that to have the data pull from your XML file.

For pushpin clustering, out of the box you can have it expand clusters when you cross an altitude threshold. For that take a look at this thread: http://bingmapswpf.codeplex.com/Thread/View.aspx?ThreadId=50772

You could also use similar logic from VEPushPin.cs to implement manual clustering on pin click.

 

Apr 9, 2010 at 7:31 PM
Edited Apr 9, 2010 at 7:35 PM

Thanks for reply. I did databinding for pushpins to my datasource which pulls data from xml. But the pushpins are not getting displayed on the map. don't know if i am missing anything. Its a surface application and i mapped wpf controls to surface controls.

<map:SurfaceVEMap x:Name="map"  MapStyle="Hybrid"  LatLong="38.9444195081574,-77.0630161230201"  ItemsSource="{Binding Locations}"  ItemTemplateSelector="{StaticResource templateSelector}"  > </map:SurfaceVEMap>

DataModel.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Xml.Linq;

namespace WorldSales1
{
    public class DataModel : INotifyPropertyChanged
    {
        #region Properties

        private ObservableCollection<City> _locations;
        public ObservableCollection<City> Locations
        {
            get
            {
                return _locations;
            }
        }

       #endregion

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        protected void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged == null)
                return;

            PropertyChanged(this, new PropertyChangedEventArgs(info));
        }

        #endregion

        #region Constructors

        public DataModel()
        {
            InitData();
        }

        public void InitData()
        {
            ObservableCollection<City> newLocations = new ObservableCollection<City>();
            XDocument sale = XDocument.Load(@"../../Resources/US Anual Sale.xml");
            var cityData = from c in sale.Descendants("City")
                           select new
                           {
                               latitude = c.Attribute("Latitude").Value,
                               longitude = c.Attribute("Longitude").Value,
                               name = c.Attribute("name").Value,
                               sales_revenue = c.Attribute("sales_revenue").Value,
                               target_Sales = c.Attribute("target_Sales").Value                             
                           };
            foreach (var item in cityData)
            {
               
                City c = new City(Convert.ToDouble(item.latitude), Convert.ToDouble(item.longitude), item.name, Convert.ToDouble(item.target_Sales), Convert.ToDouble(item.sales_revenue));
                newLocations.Add(c);
            }           
            _locations = newLocations;
            NotifyPropertyChanged("Locations");
        }
        #endregion
    }
}

Please help.

Apr 12, 2010 at 3:26 PM

Was able to get the pushpind rendered using the patch bingmapswpf-39350. Thanks

Jun 18, 2010 at 12:37 PM

I am looking for the similar thing on having a Surface demo where I can list all restaurant in a particular area.

Do you have a sample surface app starting point that I can start from and custpmose it for my own on how to do this ?
I am quite new in this geo localisation stuff and a customer ask me for a basic demo

Thnaks for help
regards

Serge

Jun 21, 2010 at 6:05 AM
I have an XML file which contains nodes which look like this:
<Sales>
    <Year>2007</Year>
    <Quarter>Q1</Quarter>
    <Month>1</Month>
    <State>California</State>
    <State_Latitude>36.778261</State_Latitude>
    <State_Longitude>-119.4171324</State_Longitude>
    <City>Los Angeles</City>
    <City_Latitude>34.025348</City_Latitude>
    <City_Longitude>-118.234863</City_Longitude>
    <Store>e-FashionLos Angeles</Store>
    <Store_Latitude>34.02</Store_Latitude>
    <Store_Longitude>-118.23</Store_Longitude>
    <Product>Accessories</Product>
    <Category>Belts,bags</Category>
    <Sub_Category>Satin Belt</Sub_Category>s
    <Units_Sold>6</Units_Sold>
    <Units_Available>32</Units_Available>
    <Sales_Revenue>4525.9</Sales_Revenue>
    <Target_Revenue>2510</Target_Revenue>
  </Sales>
Here col is the c# object which contains all the xml nodes
private List CreatePushPinsCollection(IEnumerable col, LocationLevel level, ColorCode code)
        {
            List pushPinCol = new List();
            String color = Enum.GetName(typeof(ColorCode), code);
            SolidColorBrush brush = new SolidColorBrush();
            brush.Color = Helper.ColorFromHexValue(color);

            switch (level)
	        {
		        case LocationLevel.State:
                    foreach (SalesReport obj in col)
                    {
                        SurfaceVEPushPin statePushPin = new SurfaceVEPushPin(new VELatLong(Convert.ToDouble(obj.State_Latitude), Convert.ToDouble(obj.State_Longitude)));
                        statePushPin.Tag = obj;
                        statePushPin.Content = new TextBlock
                        {
                            Text = obj.State,
                            TextWrapping = TextWrapping.Wrap,
                            FontSize = 20
                        };
                        statePushPin.MaxAltitude = dataModel.stateMaxAltitude;
                        statePushPin.MinAltitude = dataModel.stateMinAltitude;
                        statePushPin.PushPinBackground = brush;
                        statePushPin.Click += new EventHandler(SurfacePushPin_Click);
                        pushPinCol.Add(statePushPin);
                    }
                 break;
                case LocationLevel.City:
                     foreach (SalesReport obj in col)
                     {
                         SurfaceVEPushPin cityPushPin = new SurfaceVEPushPin(new VELatLong(Convert.ToDouble(obj.City_Latitude), Convert.ToDouble(obj.City_Longitude)));
                         cityPushPin.Tag = obj;
                         cityPushPin.Content = new TextBlock
                         {
                            Text = obj.City,
                            TextWrapping = TextWrapping.Wrap,
                            FontSize = 20
                         };
                         cityPushPin.MaxAltitude = dataModel.cityMaxAltitude;
                         cityPushPin.MinAltitude = dataModel.cityMinAltitude;
                         cityPushPin.PushPinBackground = brush;
                         cityPushPin.Click += new EventHandler(SurfacePushPin_Click);
                         pushPinCol.Add(cityPushPin);
                     }
                 break;
                case LocationLevel.Store:
                     foreach (SalesReport obj in col)
                     {
                         SurfaceVEPushPin storePushPin = new SurfaceVEPushPin(new VELatLong(Convert.ToDouble(obj.Store_Latitude), Convert.ToDouble(obj.Store_Longitude)));
                         storePushPin.Tag = obj;
                         storePushPin.Content = new TextBlock
                         {
                             Text = obj.Store,
                             TextWrapping = TextWrapping.Wrap,
                             FontSize = 20
                         };
                         storePushPin.MaxAltitude = dataModel.storeMaxAltitude;
                         storePushPin.MinAltitude = dataModel.storeMinAltitude;
                         storePushPin.PushPinBackground = brush;
                         storePushPin.Click += new EventHandler(SurfacePushPin_Click);
                         pushPinCol.Add(storePushPin);
                     }
                 break;
                default:
                 break;
	        }
           return pushPinCol;
        }
Let me know if it does not make any sense :-)
Jun 21, 2010 at 11:05 AM

Thnaks for you reply.

So according to your code I guess that on your Surface Application you have a kind of selector which allows you to display State, City or Store right ?

regards

serge

Jun 21, 2010 at 11:12 AM
You got it right...
Initially we will show states, zoom in in you get cities and then stores.
Is this similar to your req.?
let me know if you need more info
On Mon, Jun 21, 2010 at 3:36 PM, sergecalderara <notifications@codeplex.com> wrote:

From: sergecalderara

Thnaks for you reply.

So according to your code I guess that on your Surface Application you have a kind of selector which allows you to display State, City or Store right ?

regards

serge

Read the full discussion online.

To add a post to this discussion, reply to this email (bingmapswpf@discussions.codeplex.com)

To start a new discussion for this project, email bingmapswpf@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com


Jun 21, 2010 at 11:29 AM

Partly yes.

But how the zoom in knows that starting from state it has to displays cities ?
is it becasue you place all of them for the init phase on the map and then bing is hndling this itself ?

My scenario is as follow :

I would like to display this "Your are Here" info with current location of where I am on the map
Then initial operation is that the zoom in goes to that "You are here" location.

At that time users around surface should be individually have the possibilities to show their own request like :

User1 select restaurants : restaurant should be pushpin
User2 select bank : bank should be pushpin

The selection from User 1 and User 2 could be identify by different pushpin colors.
Then when a user have a Surface_Contact_Down on the pushpin, some more details of the puship gets displayed.

At a final if the user is interresting on that restuarant it should be able to get the direction from the "You are here point" until the his selection and be abel to save that info on its mobile.
This is my whole scenario.

I guess displaying pushpin should not be a trouble a ccording to what you explain me.
Then direction I have damned no idea how to get them and drop in a mobile is also another story.

This type of application is completly new for me and as I need to build that demo ofr a customer it has to be quite real

Any tips or ideas how to do ?

 

 

 

Jun 21, 2010 at 12:18 PM
It all depends on the altitude of the pushpins.
The max altitude of the state pushpin is equal to the min altitude of the city pushpin.
public double stateMaxAltitude = 9999500;
        public double stateMinAltitude = 5999500;
        public double cityMaxAltitude = 5999500;
        public double cityMinAltitude = 2999500;

So, when zoomed-in the state pushpin disappears and city pushpin appears.
 
There should be something to get the route between two latitude/longitude. You can explore that.
You can create an image of the route drawn and transfer that on the mobile.
 
On Mon, Jun 21, 2010 at 3:59 PM, sergecalderara <notifications@codeplex.com> wrote:

From: sergecalderara

Partly yes.

But how the zoom in knows that starting from state it has to displays cities ?
is it becasue you place all of them for the init phase on the map and then bing is hndling this itself ?

My scenario is as follow :

I would like to display this "Your are Here" info with current location of where I am on the map
Then initial operation is that the zoom in goes to that "You are here" location.

At that time users around surface should be individually have the possibilities to show their own request like :

User1 select restaurants : restaurant should be pushpin
User2 select bank : bank should be pushpin

The selection from User 1 and User 2 could be identify by different pushpin colors.
Then when a user have a Surface_Contact_Down on the pushpin, some more details of the puship gets displayed.

At a final if the user is interresting on that restuarant it should be able to get the direction from the "You are here point" until the his selection and be abel to save that info on its mobile.
This is my whole scenario.

I guess displaying pushpin should not be a trouble a ccording to what you explain me.
Then direction I have damned no idea how to get them and drop in a mobile is also another story.

This type of application is completly new for me and as I need to build that demo ofr a customer it has to be quite real

Any tips or ideas how to do ?

 

 

 

Read the full discussion online.

To add a post to this discussion, reply to this email (bingmapswpf@discussions.codeplex.com)

To start a new discussion for this project, email bingmapswpf@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com


Coordinator
Jun 21, 2010 at 5:30 PM

Jainnikita11, Thanks for helping out on the forums!

Serge,

For finding the route you need to call a Bing Maps web service and then add polylines to your map. This thread has some more information and sample code:

http://bingmapswpf.codeplex.com/Thread/View.aspx?ThreadId=58327

For sending data to a mobile device, that is a tricky thing and no one has really done it well. If you are not being paid for this POC or are on a small budget, I'd highly recommend that you mock it up and just show dragging a pushpin or route to a container on the Surface and saying "then by magic it will show up on your mobile device" but not doing it yet. Of course, then you're on the hook to develop that!

You can take a look at the recently released Surface Bluetooth Connect sample which uses standard bluetooth file transfer and doesn't require a client app on the phone:

http://blogs.msdn.com/b/surface/archive/2010/06/15/microsoft-surface-bluetooth-connect-code-sample-now-available-for-download.aspx

If you aren't sure you can implement that part, you may want to either bring in some help or convince the client to cut it. Another option that would be simpler to implement and more universal would be to offer to email the user the directions, then they can put in an email address they can access on their phone.

Hope that helps!

Jun 21, 2010 at 6:07 PM

Thnaks josh for you reply

I just look for some part of the Bing Web service and there seems to be a way which get the complete route drawn on the bing map by specifying simply a start and end location.

Based on that why is it needed to add as you said Polyline to the map ?

For mobile transfert it is a complex part and I have try this bluethooth sample for surface but it works only from the push direction and unfortunatly it is not working at all for my HTC  2 for example.
So I would probably go to a more simpler solution like email or url redirection...

let see

serge

Coordinator
Jun 21, 2010 at 6:28 PM

I haven't looked at the web services recently so there might have been changes, but I think you are referring to the service that returns a rendered static image of the route. If that meets your needs then go for it. On the other hand, if you need to add the route to the interactive InfoStrat.VE control and see it in the context of pushpins and other interface elements, then you'll need to add the polylines.