This, is so cool, I just have to spread the word. So I've been playing around with location based applications in the past few posts. I thought (as you do), wouldn't it be great to be able to continually find things of interest around your current location, i.e Pizza restaurants, coffee shops that kind of stuff.
Seeing the superb job, of how Windows Live Search Mobile I wondered how they achieved this functionality, and further more could it be 'mashed' into a Line of business application. Of course the answer is YES...
Windows Live Search is exposed as a set of web-services, how cool.. Even better still it is also possible to search by proximity. So a little digging on MSDN, I found out how to search for things near me. First stop, MSDN article, to setup the web-service and talks you through the basics:
http://msdn2.microsoft.com/en-us/library/bb251794.aspx
From this guide, weaned the following. I firstly added a web-reference to a Windows Mobile 6 Project. The web-reference URL is
http://soap.search.msn.com/webservices.asmx?wsdl
Then, I created an application ID, by going to the following -
http://search.msn.com/developer
(steps lifted from getting started guide)
Ok, so once done, I then wrote the following method, which will lookup from a given longitude and latitude of where you are a description of your choice, i.e Pizza's.
Again this C# code is proof of concept adapted from one of the MSDN examples. It returns everything as a big string, but gives you an idea for how the API works.
public string SearchIt(string searchfor,double latitude,double longitude){StringBuilder sbret=new StringBuilder();
try{
MSNSearchService s = new MSNSearchService();
SearchRequest searchRequest = new SearchRequest();int arraySize = 1;SourceRequest[] sr = new SourceRequest[arraySize];
sr[0] = new SourceRequest();sr[0].Source = SourceType.PhoneBook;sr[0].SortBy = SortByType.Distance;
searchRequest.Query = searchfor;searchRequest.Requests = sr;searchRequest.AppID = "<YOUR ID, YOU WILL NEED TO GET ONE OF YOUR OWN, SEE GETTING STARTED GUIDE";searchRequest.CultureInfo = "en-US"Location l = new Location();l.Latitude = latitude;l.Longitude = longitude;l.Radius = 1000;
searchRequest.Location = l;SearchResponse searchResponse;
searchResponse = s.Search(searchRequest);
foreach (SourceResponse sourceResponse in searchResponse.Responses){Result[] sourceResults = sourceResponse.Results;if (sourceResponse.Total > 0){sbret.AppendLine(sourceResponse.Source.ToString() + " - Total Results: " + sourceResponse.Total.ToString());sbret.AppendLine();}foreach (Result sourceResult in sourceResults){if ((sourceResult.Title != null) && (sourceResult.Title != String.Empty))sbret.AppendLine("Title: " + sourceResult.Title);if ((sourceResult.Description != null) && (sourceResult.Description != String.Empty))sbret.AppendLine("Description: " + sourceResult.Description);if ((sourceResult.Url != null) && (sourceResult.Url != String.Empty))sbret.AppendLine("URL: " + sourceResult.Url);
if (sourceResult.Location != null) sbret.AppendLine("Location: " + sourceResult.Location.Latitude + "," + sourceResult.Location.Longitude + " radius" + sourceResult.Location.Radius + ",");sbret.AppendLine("*****************************************************");}}}catch (SoapException fault){sbret.AppendLine(fault.Detail.InnerText.ToString());}catch (WebException webx){sbret.AppendLine(webx.ToString());}/* This is the end of the try...catch block. */return sbret.ToString();}
And that my friends, is pretty much it. The data is restricted to US and UK content at the moment, but it should give you a flavor of what's possible.
I was amazed as to how easy this was to get going, let me know if I've missed some big step, or something but it works like magic for me.
Theme design by Jelle Druyts
Pick a theme: BlogXP calmBlue
My Virtual Earth Balloon Races www.racingballoon.com Richard JonesPowered By The Fridge Server