Show distance in meter between Location LatLong and actual position

Hi,

I'm showing in a data grid a list of locations, each of which has its own Latitude and Longitude.

1) I have to add an unbound column with the distance in meter between the location and the actual GPS position of the device

I'm able to calculate the distance between two GPS coordinates, but how can I "bound" the column with the function that calculates the distance?

2) I have to refresh dynamically the distance cell as the actual position changes

How can I refresh the column (and not the whole grid) as the position changes?

Thank you.

Claudio

3 Replies

SK Suriya Kalidoss Syncfusion Team March 14, 2018 02:03 AM UTC

Hi Claudio, 
 
Thank you for using syncfusion products. 
 
We have checked your query. Please find the response for below queries 
Query 1:  
  If you want to load any other custom data in the unbound column then you can populate that data using the QueryUnboundColumn event. Refer below code for more details.  
 
dataGrid.QueryUnboundColumnValue += DataGrid_QueryUnboundColumnValue; 
 
private void DataGrid_QueryUnboundColumnValue(object sender, GridUnboundColumnEventsArgs e) 
{ 
    if (e.UnboundAction == UnboundActions.QueryData) 
    { 
       var Distance = Convert.ToInt16(e.Record.GetType().GetProperty("Distance").GetValue(e.Record)); 
                var Distance2 = Convert.ToInt16(e.Record.GetType().GetProperty("Distance2").GetValue(e.Record)); 
                var Total = Distance * Distance2; 
                e.Value = Total; 
    } 
} 
 
 
Please refer the below UG links.  
 
 
Query 2: SfDataGrid has support for runtime-updates. The cell value refreshes automatically if the properties in the underlying collection are implemented from INotifyPropertyChanged. Refer below code for more details.  
  public int Distance 
        { 
            get { return distance; } 
            set 
            { 
                this.distance = value; 
                RaisePropertyChanged("Distance"); 
            } 
        } 
 
        public event PropertyChangedEventHandler PropertyChanged; 
 
        private void RaisePropertyChanged(string name) 
        { 
            if (PropertyChanged != null) 
                this.PropertyChanged(this, new PropertyChangedEventArgs(name)); 
        } 
 
We have also attached sample for your reference. 
 
 
Regards, 
Suriya. 



CR CLAUDIO RICCARDI May 12, 2018 05:04 PM UTC

Thank you for the support,

actually, the "property" that raises the event PropertyChange is not a property of the Model but my GPS position, so when I change my position (using for example the app on a car), the value on the grid unbound column has to change.

How can I use your sample code tho implement this?

Best regards.

Claudio Riccardi


AN Ashok N Syncfusion Team May 17, 2018 05:29 PM UTC

Hi Claudio, 

 

In our SfDataGrid we have perform all the grid operation using Mapping name only. In UnboundColumn Expression or GridUnboundColumnEventArgs.Value has been calculated based on the Model object. We request you to set newly updated value to model object. We have prepared the sample based on this and attached in the below location, please refer it.


Sample: GettingStarted_2e74ce05.zip

 

Regards,

Ashok



Loader.
Up arrow icon