lundi 8 juin 2015

MVC3 SQL query get approximation of GPS

A little background I am programming android but using MVC 4 web api and SQL server. I am creating a program that gets GPS coordinates from users phone: I obtain the latitude and longitude of their location every 20 minutes. I have an SQL database with about 20,000 rows which contains 4 fields: Latitude, Longitude, City, State. My question is given a particular latitude and longitude how can I query the database to obtain the closes latitude and longitude so that I can tell them which city/town they are in?

This is what I got so far and it is wrong because I am looking for the closest approximation because all of the GPS lats,longs will not exactly be equal to the ones in the database any suggestions would be great

   public ActionResult getLocation(double latitude,double longitude)
        var myloc = (from s in db.zipss where s.latitudes == latitude && s.longitudes == longitude select s).FirstOrDefault();
        return View(myloc);

Aucun commentaire:

Enregistrer un commentaire