Xamarin Forms Maps on Windows Phone 8.1

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:-

MapsTest on Windows Phone Emulator

MapsTest on Windows Phone Emulator

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.

Advertisements

Windows Live Local goes live

As the name suggests, Windows Live Local (the new name for MSN Virtual Earth) is now live. It has a fresh new look, mapping data for Europe (woohoo!), supports driving directions, custom pushpins and for a selection of US cities it has high quality “birds-eye” images. There have been some changes to the API in this version, full details of which are due to hit MSDN today.

New MSN APIs to debut Tuesday

[Via MP2KMag.com]


At PDC on Tuesday (13th) Microsoft will unveil a new collection of APIs for it’s MSN services to be available from http://msdn.microsoft.com/msn, these will include:-



  • MSN Search Web Services
  • MSN Messenger Activity API (already available here)
  • MSN Virtual Earth API

The last item is interesting. Firstly it sounds like this will be a “proper” documented API, rather than the jscript hacks currently available. Secondly it is being offered free for both commercial and non-commercial use. It is interesting therefore to see how it stacks up against it’s big brother Mappoint Web Service for simple commercial applications.


Speaking of which, the new version of Mappoint Web Service (4.0) will also be released at PDC. New features include support for polygons, some new map styles, and further extensions to the mapping coverage.


[Update] MWS 4.0 SDK is available:-


http://www.microsoft.com/downloads/details.aspx?FamilyID=cb5148a9-f09e-4ec8-992f-16478c0b5d9a&DisplayLang=en

Developing with Virtual Earth

Now that the hype has died down on Virtual Earth it is interesting to see what developers are doing with the product even though it doesn’t expose any kind of developer API. The best place to start is at Dr Neil’s site Via Virtual Earth. There are a few articles here showing how to pull maps from virtual earth onto your own website. To a user outside the US the mapping detail available is a bit lacking, you get quite a selection of place names, but no roads and satellite imagery only at a very high level.


Hopefully the technologies demonstrated in Virtual Earth will permeate through to the Mappoint Web Service, as the dynamic pan and zoom, imagery and pushpin labels are quite impressive.

How They Beta Test Mappoint Products

Ever wondered how Microsoft test their location products? I mean it’s not like you can test them in every possible location. Well two guys in Great Britain are trying to come close by driving the length and breadth of Great Britain passing through key points as they go – They have already covered the furthest South, East and West already. You can track their progress on a special blog and win a copy of Autoroute with GPS receiver if you estimate their mileage.


Autoroute 2006 (European version of Streets & Trips) is due out in October, no details of features for the new release have been announced yet.