Some time ago Xamarin added support for Windows Phone 8.1 (and Windows 8.1) platforms to Xamarin Forms. I wrote a blog post about how to configure your project to run your Xamarin Forms app in a Windows Phone 8.1 project.
Alongside the base Xamarin Forms API there is a Xamarin Forms Maps component which, as the name suggests, adds cross-platform mapping support for Xamarin Forms applications. However there is a catch, in the current version (1.5 at the time of writing this) only Windows Phone Silverlight is supported. So while you can target Windows Phone 8.1 with Xamarin Forms you can’t use the Xamarin Forms Maps functionality.
With most controls there is a standard way to write a custom renderer to provide an implementation for a particular platform. Quite often these are not too complex – just mapping properties from a Xamarin Forms control to the native equivalent. Windows Phone 8.1 has a Map control built in so I set about writing a renderer.
It wasn’t quite as straight-forward as I originally anticipated and it took a while to work out what the other platform implementations were doing but I got it to a point where 99% of the functionality is supported so decided to release the code ( on GitHub here ) and the compiled library ( on NuGet here ).Usage
You can get up and running very quickly. You merely need to add the NuGet package to your Windows Phone 8.1 project and add one line of code:-InTheHand.FormsMaps.Init([MAP_TOKEN]);
Place this in the OnLaunched method in your App.xaml.cs file. [MAP_TOKEN] is a string which you can get for your app from the Windows Dev Center. For debugging/test purposes you can pass null here and the map will display a banner indicating it is running without a token. I designed this to be as similar as possible as the other Xamarin.Forms.Maps platforms. Only the namespace is different. No changes are necessary to your PCL project to support this.Sample
There is a sample app in the GitHub repository which adds some food and drink pushpins to Birmingham. This is how it looks on Windows Phone:-
As well as supporting the Map control itself the library also provides an implementation for the Geocoder class. This allows you to fetch an address (or addresses) for a given position or to lookup a location for a given address. I haven’t currently added this to the sample project, but there is nothing special to do here – it “just works” from your platform independent code.What’s Not In This Version
The only real thing I didn’t put into this version was the ability to use different pushpin icons depending on the type of PushPin – Xamarin supports Generic, Place, SavedPin and SearchResult. All currently use the default image which you can see from the above screenshot.Thanks
My last word is to say thanks to those who offered to test this and provided feedback on the initial build. I hope you’ll find this useful to easily add mapping to your Xamarin Forms projects on Windows Phone.
- 3CSS布局(六) 对齐方式
- 6Java 解决IE浏览器下载文件，文件名出现乱码问
- 8Spring学习之旅（八）Spring 基于AspectJ注解配
- 9Leetcode 1. Two Sum (java)