Windows Phone – Embedded fonts and Bing maps
Today I would like to illustrate about how I can embed font and Bing maps into Windows Phone application. I know it’s a such simple example that every programmer on Windows Phone can write but I just want to make a demo to show that we can use embedded font and host a Bing map control. For Bing map example, I use this example http://www.earthware.co.uk/blog/index.php/2010/03/writing-a-bing-maps-location-aware-application-for-windows-phone-7-series/ with some modifications so that I can relatively find my location on Bing map.
Embedded fonts
Silverlight allows us to embed font in application without installing it on operating system. Using custom font makes GUI of application really beautiful and creative. To embed font, copy it to a folder of your project, set “Build Action” to “Content” and link to control as following
<TextBlock FontFamily="Fonts/AnnabelScript.ttf#Annabel Script" Text="Duration" x:Name="txtDuration" Margin="20,530,173,82"/>
Bing maps
To use Bing map control, you can read the example above. I just tell which I learned when I was trying to use Microsoft.Maps.MapControl library. It’s really very strange. After adding reference to Microsoft.Maps.MapControl, if I add this reference in XAML first
xmlns:bing="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl"
Then I can not use Map control in XAML.
<bing:Map Name="mapMain" NavigationVisibility="Collapsed" Mode="AerialWithLabels" CredentialsProvider="USE_YOUR_BING_MAP_KEY" Height="577"> <bing:MapLayer> <Ellipse Fill="Red" Width="20" Height="20" bing:MapLayer.Position="0,0" Name="ppLocation" Visibility="Collapsed" /> </bing:MapLayer> </bing:Map>
Visual Studio says that it can not find Map control and asks if I forget to add reference to assembly. But if I use Map control in XAML first and add reference later then everything works.
private void btnBrowse_Click(object sender, RoutedEventArgs e)
{
GetLocationOfCity();
}
private void GetLocationOfCity()
{
string strGetIpUrl = "http://www.whatismyip.com/automation/n09230945.asp";
WebClient wcIP = new WebClient();
wcIP.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wcIP_DownloadStringCompleted);
wcIP.DownloadStringAsync(new Uri(strGetIpUrl, UriKind.Absolute));
}
void wcIP_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
string strIP = e.Result;
string strLocation = "http://api.hostip.info/?ip=" + strIP + "&position=true";
WebClient wcLocation = new WebClient();
wcLocation.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wcLocation_DownloadStringCompleted);
wcLocation.DownloadStringAsync(new Uri(strLocation, UriKind.Absolute));
}
void wcLocation_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
string strResult = e.Result;
string strOpenTag = "<gml:coordinates>";
int nStartIndex = strResult.IndexOf(strOpenTag) + strOpenTag.Length;
string strClosedTag = "</gml:coordinates>";
int nEndIndex = strResult.IndexOf(strClosedTag);
string strCoordinates = strResult.Substring(nStartIndex, nEndIndex - nStartIndex);
double longtitude = Convert.ToDouble(strCoordinates.Split(',')[0]);
double latitude = Convert.ToDouble(strCoordinates.Split(',')[1]);
Location locCurrent = new Location(latitude, longtitude);
mapMain.SetView(locCurrent, 15);
MapLayer.SetPosition(ppLocation, locCurrent);
ppLocation.Visibility = System.Windows.Visibility.Visible;
}
As you can see, because the location service is not available with emulator cause of lacking GPS device. I modify the example by getting my IP address through service of whatismyip and then pass my IP to service of hostip to get the longitude and latitude of that IP. With these information I can use Bing map control to navigate to my location but it’s not exact 100%. I hope with a real phone and GPS device, the Bing map can locate exactly where I am.
You can download the source code of Bing map example “Windows Phone Bing Map“
Popularity: 2% [?]

Good work on adding in the ip location, any chance of making our original article actually a clickable link?
@Brian: Yes of course if you want.
Code is not availble..Please check it Once
Hi,
I am not getting the \gml:coordinates\ in the wcLocation_DownloadStringCompleted event…in the e.Result, gml:coordinates under ipLocation node is not there.
Thanks
RK
@RaviKumar: The web service which I used, is a free one. Maybe your city is not supported. Try to access it directly from your browser and see if your needed information is there.
Is there a way to have an embed map of bing using the bird’s eye view but zoomed out? The default zoom is too close and can’t really show the whole neighborhood.
Leave your response!
Computer security »
Hacking – How to hack WPA/WPA2 Password with BackTrack through cracking WPS?
Last week I’ve read small news on c’t magazine saying that the default password of EasyBox router used for Vodafone, Telecom, Arcor in Germany … was hacked by Sebastian Petters. That means if someone is using default settings of EasyBox, you can get his WLAN password easily and then access his network. This default password was generated by a algorithm and this algorithm was patented. Therefore like other patents, the complete description of algorithm was …
Programming »
C# – Host Microsoft Chart in WPF application
How we provide our customers the way to display their data is a important feature of every software for data management. Maybe the users want to use Bar, Line, Pie, Pyramid chart… someone wants to display as 2D and the other wants 3D for his plotting. The financial prefer Kagi, Renko, Point and Figure chart… meanwhile the statisticians maybe use Bar and Column, Cylinder or just simple Line chart. Because of these numerously different requirements …
Tutorial »
Tools – Doidw – Do I DDos this website?
Last year I have seen a lot of DDOS attacks aimed to website of news or independent communities. These websites were attacked by a botnet built from unknown virus (which wasn’t detected by any antivirus at that time). Some professionals found some variants of this virus but the websites were still heavily attacked.
Some of professional users are willing to help to find more variants of this virus. They would like to check if computers of …
Donation
Archives
Blogroll
Tag Cloud
.net reactor 64 bit 2012 asp.net auto backtrack blog c# codeveil 3.x database Entertainment firefox game gold hack hacking master volume munich mvvm online notes password pet php picasa reverse engineering security sharepoint silverlight ssh theme tlbb tool trip visual studio wallpaper wcf web album webpart web service windows windows 7 windows phone word wpf yahoo messengerRecent Posts
Most Commented
Most Popular