yamspog
yamspog

Reputation: 18333

how to use azure mobile services to find a location near you

I'm using Azure Mobile Services to store a list of locations that each have a latitude/longitude. This list may contain thousands of locations spread across the country.

When the application starts up, I want to find the list of locations that are 'close' to my current location (say within 5 km).

I tried the following statement:

items = await _itemTable.Where( item => 
    ((Math.Abs(item.Latitude - LastUserLocation.GeoPoint.Latitude) < 0.001) &&
     (Math.Abs(item.Longitude - LastUserLocation.GeoPoint.Longitude) < 0.001))
     ).ToListAsync();

but got an error that basically states that Math.Abs cannot be used. Looking at documentation closer and it appears that the operations that you can place in the Where clause is pretty limited.

So, anyone have suggestions on how to solve this issue?

Upvotes: 1

Views: 799

Answers (2)

Chris
Chris

Reputation: 3017

As of right now, the support for geolocation with Azure Mobile Services isn't exactly turnkey. That being said, it's not a very hard thing to accomplish. Essentially you'll need to pass over the latitude and longitude values to your table endpoint / custom API and use those as parameters to a custom SQL query that you execute using the mssql module. There is a great example of doing just about exactly what you want to do here: http://code.msdn.microsoft.com/windowsapps/Geolocation-sample-end-to-5d9ee245.

Upvotes: 1

Anthony Chu
Anthony Chu

Reputation: 37520

I would move this into a custom API call that takes in the lat/long and returns a list of locations. You can try to port your query logic to JavaScript and run it on the server side.

But you can actually take advantage of SQL Database's Geography column type and its geospatial capabilities to perform the calculations for you. Here's a step by step on how to do this...

http://code.msdn.microsoft.com/windowsapps/Geolocation-sample-end-to-5d9ee245

Upvotes: 0

Related Questions