EDN Admin
Well-known member
Todays Mobile Monday post is one that I thought could dispatch a number of birds with a single post... Show off a kind of cool OData data source How to use your location and others to see how "close" you are Help you find your local Windows Phone Champion Give you an app, with source, that brings both of those together http://windowsteamblog.com/windows_phone/b/wpdev/archive/2012/02/17/find-my-champ.aspx" target="_blank Find My Champ <blockquote> What do you think of when you hear the word “Champ”? Someone who is the best? A sports champion? How about someone who fights for a cause? Here at Microsoft we have employees called “Developer Evangelists”. Part of their job is to help get the word out about Microsoft products and technologies. The other part of their job is to champion our developers. Here in Windows Phone we call our evangelists “Phone Champs”. Champs ensure our developers get exactly the help & support they need and are the voice of the developer community. They are all experts on our platform and serve as local resources to answer questions from current or prospective developers. Champs can help you troubleshoot a problem in your app and can help you get your hands on a phone for testing. Oh, and some of our Champs are really funny and can tell you a good joke or two. <img src="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-84-metablogapi/2210.wlEmoticon_2D00_smile_5F00_4904DFAD.png" alt="Smile So how do you find one of our great Phone Champs? Today I’m happy to announce a new application to help you find them. We originally wanted to call the app “Champ Acquisition and Discovery 1.0 for Workgroups Windows Phone Edition.” Luckily cooler heads prevailed and we’re calling it “Find My Champ”. ... Get the App Go http://findmychamp.codeplex.com/ download the app’s source code . Compile the code in our http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=27570 dev tools and side-load Find My Champ onto your developer device or into the emulator. The app will also be in the Marketplace soon for you to download. Find your local Phone Champ and get in touch with them. Ask them for help with your app or to let you know about events or hackathons in your area. We’d love to get your feedback on the Find My Champ application. Tell us what we can do to make it more useful. You can also come help us improve the app on http://findmychamp.codeplex.com/ Codeplex . Additionally, I suspect that many of you will have creative ideas for how to use the http://champ.cloudapp.net/ChampDataService.svc Champs OData feed in other applications, mashups, etc. Please let me know what you create! </blockquote> The first thing that I thought was cool was that this is backed on an http://champ.cloudapp.net/ChampDataService.svc OData feed . This means that if we, the development community want to present our own view of the data, in our own apps, we can very easily. Using the http://champ.cloudapp.net/ChampDataService.svc OData feed is very easy. Heres a snap from the must have http://www.linqpad.net/" target="_blank LINQPad utility querying the feed. http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/SNAGHTML13e2501a%5B3%5D.png" target="_blank <img title="SNAGHTML13e2501a" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/SNAGHTML13e2501a_thumb.png" alt="SNAGHTML13e2501a" width="650" height="283" border="0 LINQPad makes it almost too easy to play with this feed. Say I want all the Champs with a Last Name starting with E, order by LastName? http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image%5B2%5D-35.png" target="_blank <img title="image" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image_thumb-34.png" alt="image" width="650" height="327" border="0 Or who have a MSDN blog and also have a Twitter account? http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image%5B5%5D-15.png" target="_blank <img title="image" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image_thumb%5B1%5D-43.png" alt="image" width="650" height="398" border="0 Okay, OData via Linq is cool, but what if you want the actual OData URL for this query? Again, LINQPad makes that click easy. Just click on the "SQL" right above the results; http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image%5B11%5D-17.png" target="_blank <img title="image" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image_thumb%5B3%5D-29.png" alt="image" width="650" height="169" border="0 Then to maybe finally blow your mind, did you know Notepad can open URLs? http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image%5B14%5D-14.png" target="_blank <img title="image" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image_thumb%5B4%5D-29.png" alt="image" width="650" height="389" border="0 http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/SNAGHTML13ec4a22%5B3%5D.png" target="_blank <img title="SNAGHTML13ec4a22" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/SNAGHTML13ec4a22_thumb.png" alt="SNAGHTML13ec4a22" width="650" height="295" border="0 So were got the data, lets check out the http://findmychamp.codeplex.com/SourceControl/list/changesets" target="_blank app source . First, when you download the source, youll need to add one reference, easily done via NuGet. When you first open the Solution youll see this (if you expand the given items). Note the warning/missing icons; http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image%5B18%5D-7.png" target="_blank <img title="image" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image_thumb%5B6%5D-21.png" alt="image" width="204" height="427" border="0 Fire up NuGet and search for "SilverlightToolkitWP" http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/SNAGHTML13eefd5a%5B3%5D.png" target="_blank <img title="SNAGHTML13eefd5a" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/SNAGHTML13eefd5a_thumb.png" alt="SNAGHTML13eefd5a" width="610" height="407" border="0 Click install. Thats it. You should now be good to go and able to run the app in the Emulator. http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image%5B21%5D-7.png" target="_blank <img title="image" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image_thumb%5B7%5D-19.png" alt="image" width="244" height="407" border="0 http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image%5B27%5D-3.png" target="_blank <img title="image" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image_thumb%5B9%5D-14.png" alt="image" width="244" height="407" border="0 http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image%5B24%5D-5.png" target="_blank <img title="image" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image_thumb%5B8%5D-15.png" alt="image" width="244" height="407" border="0 http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image%5B39%5D-1.png" target="_blank <img title="image" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image_thumb%5B13%5D-5.png" alt="image" width="244" height="407" border="0 http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image%5B42%5D-2.png" target="_blank <img title="image" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image_thumb%5B14%5D-1.png" alt="image" width="244" height="407" border="0 When first running the app in the Emulator, the Local list will be this default list. If you want to see the local people for a given location, set the location and then re-run the app (refresh doesnt yet seem to take a change in location into account). So here I set the location; http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image%5B33%5D-1.png" target="_blank <img title="image" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image_thumb%5B11%5D-8.png" alt="image" width="463" height="407" border="0 Then exit and re-run the app in the Emulator. http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image%5B30%5D-3.png" target="_blank <img title="image" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image_thumb%5B10%5D-6.png" alt="image" width="650" height="364" border="0 Set to another location, exit and rerun the app. You dont need to kill the emulator or debugging session, just re-run it in the emulator (if that makes sense?) http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image%5B36%5D.png" target="_blank <img title="image" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image_thumb%5B12%5D-4.png" alt="image" width="650" height="362" border="0 The source is pretty easily readable and spelunkable; http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image%5B49%5D.png" target="_blank <img title="image" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image_thumb%5B17%5D-2.png" alt="image" width="220" height="427" border="0 Data binding is used as you would expect. http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/SNAGHTML13fb2831%5B3%5D.png" target="_blank <img title="SNAGHTML13fb2831" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/SNAGHTML13fb2831_thumb.png" alt="SNAGHTML13fb2831" width="650" height="360" border="0 One of the things I thought key was how "local" was determined. How was your location and the Champs Lat/Longs used to determine "local?" <pre class="brush: csharp public static double GetDistance(double fromLatitude, double fromLongitude, double toLatitude, double toLongitude)
{
int earthRadius = 6371; // earths radius (mean) in km
double chgLat = DegreeToRadians(toLatitude - fromLatitude);
double chgLong = DegreeToRadians(toLongitude - fromLongitude);
double a = Math.Sin(chgLat / 2) * Math.Sin(chgLat / 2) + Math.Cos(DegreeToRadians(fromLatitude)) * Math.Cos(DegreeToRadians(toLatitude)) * Math.Sin(chgLong / 2) * Math.Sin(chgLong / 2);
double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
double d = earthRadius * c;
return d;
}
private static double DegreeToRadians(double value)
{
return Math.PI * value / 180.0;
}
[/code] <pre class="brush: csharp private void UpdateDistance()
{
if (GeoData.Status != GeoPositionStatus.Ready)
return;
// when position is updated, update distance
var _FromLat = GeoData.Location.Latitude;
var _FromLong = GeoData.Location.Longitude;
var _ToLat = (double)Latitude;
var _ToLong = (double)Longitude;
this.DistanceAway = FMCLocation.GetDistance(_FromLat, _FromLong, _ToLat, _ToLong);
}
// this is the same as PropertyChanged("Distance"), just easier to use
public event EventHandler DistanceChanged;
private double m_DistanceAway;
public double DistanceAway
{
get { return m_DistanceAway; }
set
{
m_DistanceAway = value;
OnPropertyChanged("DistanceAway");
OnPropertyChanged("IsLocal");
if (DistanceChanged != null)
DistanceChanged(this, EventArgs.Empty);
}
}
public bool IsLocal { get { return (DistanceAway > 0 && DistanceAway < 250); } }
[/code] If youre looking for help in building your Windows Phone 7 applications and are looking for help, think about contacting your local Champ. Thats part of their job and desire, to be there to help you. Finding them, is now super easy, via this app (which you have to agree is kind of meta-cool... <img src=http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif?v=c9 alt=Smiley /> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Feeds/RSS&WT.dl=0&WT.entryid=Entry:RSSView:1fe6e819b562467c92ea9ffb01654359
View the full article
{
int earthRadius = 6371; // earths radius (mean) in km
double chgLat = DegreeToRadians(toLatitude - fromLatitude);
double chgLong = DegreeToRadians(toLongitude - fromLongitude);
double a = Math.Sin(chgLat / 2) * Math.Sin(chgLat / 2) + Math.Cos(DegreeToRadians(fromLatitude)) * Math.Cos(DegreeToRadians(toLatitude)) * Math.Sin(chgLong / 2) * Math.Sin(chgLong / 2);
double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
double d = earthRadius * c;
return d;
}
private static double DegreeToRadians(double value)
{
return Math.PI * value / 180.0;
}
[/code] <pre class="brush: csharp private void UpdateDistance()
{
if (GeoData.Status != GeoPositionStatus.Ready)
return;
// when position is updated, update distance
var _FromLat = GeoData.Location.Latitude;
var _FromLong = GeoData.Location.Longitude;
var _ToLat = (double)Latitude;
var _ToLong = (double)Longitude;
this.DistanceAway = FMCLocation.GetDistance(_FromLat, _FromLong, _ToLat, _ToLong);
}
// this is the same as PropertyChanged("Distance"), just easier to use
public event EventHandler DistanceChanged;
private double m_DistanceAway;
public double DistanceAway
{
get { return m_DistanceAway; }
set
{
m_DistanceAway = value;
OnPropertyChanged("DistanceAway");
OnPropertyChanged("IsLocal");
if (DistanceChanged != null)
DistanceChanged(this, EventArgs.Empty);
}
}
public bool IsLocal { get { return (DistanceAway > 0 && DistanceAway < 250); } }
[/code] If youre looking for help in building your Windows Phone 7 applications and are looking for help, think about contacting your local Champ. Thats part of their job and desire, to be there to help you. Finding them, is now super easy, via this app (which you have to agree is kind of meta-cool... <img src=http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif?v=c9 alt=Smiley /> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Feeds/RSS&WT.dl=0&WT.entryid=Entry:RSSView:1fe6e819b562467c92ea9ffb01654359
View the full article