How To used stored location in database with location calculate distance method

Gbenga Banuso Odumosu 40 Reputation points

I am working on MAUI to calculate distance between two locations. I have stored the first et of location in an sqlits database. Using Location calculate distance method, I got error Severity Code Description Project Path File Line Suppression State

Error	CS1503	Argument 1: cannot convert from 'double' to 'Microsoft.Maui.Devices.Sensors.Location'

the program

return await conn.Table<Person>().Where(s => s.location == Location.CalculateDistance(abuja,s.location < 3.0, DistanceUnits.Kilometers)).ToListAsync();
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,996 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce ( 58,126 Reputation points

    you have a couple issues.

    a Location can not be stored in a sqlite database, typically you would store the lat & long, as two double columns.

    second the where expression makes no sense. s.location < 3.0 is a bool, but the Location.CalculateDistance() has no overload with a bool.

    third the Location.CalculateDistance can not be converted to sql, so you would be need to read the table into a memory collection first:

    return (await conn.Table<Person>().ToListAsync())
       .Where(s => 
           ) < 3.0
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful