C# - Nearest Match To Array Of Doubles?

Apr 15, 2010

Given the code below, how do I compare a List of objects's values with a test value? I'm building a geolocation application. I'll be passing in longitude and latitude and would like to have the service answer back with the location closest to those values. I started down the path of converting to a string, and formatting the values down to two decimal places, but that seemed a bit too ghetto, and I'm looking for a more elegant solution.

public class Location : IEnumerable
{
public string label { get; set; }
public double lat { get; set; }
public double lon { get; set; }
//Implement IEnumerable
public IEnumerator GetEnumerator()
{
return (IEnumerator)this;
}
}
[HandleError]
public class HomeController : Controller
{
private List<Location> myList = new List<Location>
{
new Location {
label="Atlanta Midtown",
lon=33.657674,
lat=-84.423130},
new Location {
label="Atlanta Airport",
lon=33.794151,
lat=-84.387228},
new Location {
label="Stamford, CT",
lon=41.053758,
lat=-73.530979}, ...
}
public static int Main(String[] args)
{
string inLat = "-80.987654";
double dblInLat = double.Parse(inLat);
// here's where I would like to find the closest location to the inLat
// once I figure out this, I'll implement the Longitude, and I'll be set
}

View 4 Replies


Similar Messages:

Add Rounded Doubles To Label

Mar 22, 2010

I'll use the Math.Round function, but there happends something strange. If i have a numer like 10.0012356 he adds with round(10.0012356) only 10, and not the wanted 10.00 But if i have 10.534, he adds 10.53, so then its ok. How can i change that? I use this code right now:

double PriceIn = PriceExcl * ((BTW + 100)/100);
lblPriceEx.Text = "€" + Math.Round(PriceExcl, 2).ToString();
lblPriceIn.Text = "(" + Math.Round(PriceIn, 2).ToString() + "incl.)";

View 4 Replies

ADO.NET :: Stored Procedure And Decimal / Doubles

Nov 25, 2010

My web page allows customers to search products by selecting criteria. In this example, they can choose a height range (we'll use the example between height 2.00 and 2.99). The issue is, the database returns a results which has a height of 3.00 (which is obviously not between 2.00 and 2.99) I am using a stored procedure.

[Code]....

My webpage passes the paramters for @Pr and @Pr2 (which are of type double) to the stored procedure (@Pr = 2.00, @Pr2 = 2.99). My c# code (simplified - FYI, request.QuerysString["p"] returns the string value 2)

[Code]....

You can see from the C# I have commented 2 lines for debugging where I've used the dqsPr variable and where I've typed the number in manually. Regardless of sending either the variable or the actual 'number', the results remain the same (it shows a product which has a height of 3.00). If I change the Stored procedure (for debugging purposes only) Select statement to SELECT DISTINCT PartNumber, Positions, Switch, Post, Profile FROM View WHERE Height BETWEEN 2.00 AND 2.99 ORDER BY Type ASC it works fine. So, it must be due to the passing of the paramaters via ado.net?

View 4 Replies

C# - WebForms Text Input => Doubles & Strings & Booleans?

Apr 14, 2010

Is there a better way to do "input forms" in WebForms?I always end up with code like this:

Double d = 0; // chuckle inside
if(Double.TryParse(myNumberTextField.Text, out d))
{
myObject.DoubleVal = d;
}

Is there a better way to process free-form "numeric" input.

View 1 Replies

Web Forms :: UltraWebGrid Columns Data Mismatch To Nearest Column?

Feb 15, 2010

In ultrawebgrid when column data is large then it(data) comes to nearest coumn data then the mismatch. i have set all the property like width,AllowColSizingDefault="Free",SelectTypeRowDefault="Extended"

Ultra web grid code:

<igtbl:UltraWebGrid ID="UwgUsageDetails" runat="server" Height="287px" Width="100%">
<Bands>
<igtbl:UltraGridBand>
<Columns>

[Code]....

View 1 Replies

Web Forms :: Round Date Time TextBox Field To Nearest 15 Minutes?

May 19, 2010

I have a textbox that the user enters a time into, so 04:10 PM, I would like it to round to 04:15 PM, likewise 04:06 PM would Round to 04:00 PM.

Is there any built in controls that handle this, are there any code samples out there?

View 3 Replies

Social Networking :: Load And Focus Nearest Basic Amenities In Google Map

May 7, 2015

Below code shows basic amenities but my requirement is to focus on nearest basic amenity

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Locationfinder.aspx.cs" Inherits="Locationfinder" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">

[Code] .....

View 1 Replies

Add Values To Array and Replace Preexisting Array Items With New Values without The Array Changing Size?

Aug 19, 2010

I need to know what would be the best choice of array to use given the following specifications. This array's size will be predermined upon the loading of the appication. All I want to do is be able to add values to this array and replace preexisting array items with new values without the array changing size. Someone suggested that I use a Dictionary Array Object? I would appreciate any suggestions.

View 3 Replies

Make Select Statement Select Row With Nearest Values?

Oct 23, 2010

How would i make a select statement select the row with the nearest values? e.g.: I have 3 labels, labels1 2 and 3, with values of 1.2, 2 and 5.8 In my table i have 4 columns, first is the data im after, and the next 3 relate to the three labels. I want to select one row, where the values of labels match it the closest.......

View 8 Replies

Web Forms :: Getting An Array Of List From Database To Client Side(javascript Array)?

May 12, 2010

Iam getting an array of list from database to client side(javascript array). Now my aim to place those values in a div one by one and that div should attach to the textbox similar to Autocomplete extender.

View 4 Replies

Pass C# Array To Javascript Array?

Aug 12, 2010

how to pass a C# ASP.NET array to a Javascript array? Sample code will also be nice.

Let's say for simplicity that in my aspx.cs file I declare:

int [] numbers = new int[5];

now I want to pass "numbers" to the client side and use the data in the array within javascript. How would I do this?

View 4 Replies

Regexp - Converting From JS Match To C#

Feb 4, 2010

This is probably a simple one for C# people :-) I have this regular expression in javascript:

strVar = strVar.replace(/(specificattribute=)"s*([^"]+?)s*"/g, '$1"$2"');

It replaces leading and trailing spaces inside a specific attribute's value, globally (as per this example page: [URL]). I need to do the same on a string in C#, but when trying the above, the syntax checker chokes at the regExp. So I need the equivalent line of the above in C#.

View 8 Replies

Match Only Extensionless URLs?

Mar 25, 2010

I want a regex expression which only match extensionless url. In otherwords if an extension is present in url then completely ignore it.

/(.+)/(.+) this will match an URL both with and without extension.

www.site.com/sports/cricket should match

www.site.com/sports/cricket.aspx shouldn't match

View 3 Replies

C# - Match Many Cases In A Single Run?

Jan 5, 2011

So the case is this:

The user can provide a group of strings for a propert. ex:

DaysNeeded ="Sunday,Tuesday,Friday,Saturday";

In the actual UI, the days of the week are available as check boxes. I'm trying to provide a way so that the user can also set the days needed in the code behind through a property.

Now my query is, which strategy is the best way to execute certain pieces of code that are respective to the days that the user have provided. Meaning, the DaysNeeded property has sunday,Tuesday, Friday and Saturday. Each day has certain piece of code to be executed. If i have to have a forloop with a switch case for each day of the week, i feel it would cost more as i have to run the for loop, the number of days the user has given.

Is there a way that i can run a single code that matches all the set of days the user has given and run the respective code pieces?

View 3 Replies

Regular Expression For Exact Match

Mar 16, 2011

I am reading .css fle which is having following 2 css classes:

[code]....

View 11 Replies

IIS Removes If-None-Match And If-Modified-Since Headers?

Mar 1, 2010

I have an ASHX handler or an ASPX page (the problem happens in both cases).

The web client sends a request containing If-None-Match and/or If-Modified-Since headers but context.Request.Headers.Get("If-None-Match") or context.Request.Headers.Get("If-Modified-Since") is null in the handler.

The same script works in my local development machine but it doesn't work in the online machine (both are running IIS7 on Win 2008, .NET 3.5)

View 1 Replies

Object Does Not Match Target Type?

Sep 30, 2010

hav a gridview, it works when old entites are in the collection because all of these are proxies of the real entity.But if i insert a new Entity using context.User.AddObject(user);context.SaveChanges();The databind to the grid crashes with error, "Object does not match target type", because the old object are proxies of the real POCO, while the new object is of Type User

View 1 Replies

.NET CustomValidator Trying To Match To System.EventHandler?

Apr 15, 2010

<asp:TextBox runat="server" ID="Accountname" />
<asp:CustomValidator runat="server" ControlToValidate="Accountname" OnServerValidate="Accountname_CheckUnique" meta:resourcekey="ACCOUNTNAME_UNAVAILABLE" />
protected void Accountname_CheckUnique(object source, ServerValidateEventArgs arguments)
[code]...

View 1 Replies

Regular Expression To Match 10-14 Digits?

Apr 24, 2010

I am using regular expressions for matching only digits, minimum 10 digits, maximum 14. I tried:

^[0-9]

View 5 Replies

MVC :: MapRoute Does Not Match Other '-'s When '-' Is Used As A 'path Separator'?

Apr 15, 2010

I have registered the following SEO friendly route:

[Code]....

Anyone an idea how to fix this problem? Returning a 404 is not a nice UX when (in our case) only the id really matters ...

View 7 Replies

MVC :: The Incoming Request Does Not Match Any Route

Dec 17, 2010

I'm baffled as to why this error keeps popping up all the time....

i've created handlers in IIS7 to map requests for static content.

I've added the following line to my routes:

routes.IgnoreRoute("rest/schema/{file}.xsd");

I've checked that the file is physicly present on the location, yet MVC keeps bitching about not beeing able to find a route. What is the IgnoreRoute for then if it keeps searching?

View 3 Replies

Reg: Regular Expression Patterns To Match For The Example

Nov 20, 2010

I want a regular expression patterns to match for the following example.

USER@DOMAIN.COMDOMAIN\USERUSER

I need only the USER to be extracted from those.

View 2 Replies

Run Javscript From Code Behind If Some Condition Match?

Nov 22, 2010

i want to run javscript from code behind if some condition match

In page load i have a sub progrme

Private Sub Runscript()
' Execute javascript some condition match
dim i as integer=0
if i=0 then
'execute javascript alert
end if
End Sub
and javascript is
function Alert() {
alert("Hai");
}

i am calling this some sub programme Runscript in pageload

View 6 Replies

Web Forms :: Match Content On Website Using C#?

Mar 10, 2010

I need to match the content on web.For example consider I have one sample code,if i submit that code it should search on web and display the website url where that code exists. I need the code in asp.net and c#.

View 1 Replies

C# - SQL To Select Rows That Match A URL With Wildcard?

Aug 4, 2010

I have a table in the db with one column containing a URL like http://site.com/users/*/profile.I am given a URL (like http://site.com/users/234/profile) and want to select all the rows in the db that match the url (in this case * is a wildcard).

I was thinking of using Regex to do this, by replacing the * with regex for any character. But am unsure as to what the SQL or LINQ code should be for the selection.

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved