I have a UWP in which I am writing an app that can track a devices location and I have recently been trying to put an image of a map as my applications live tile using Google's static maps API. The idea is that the live tile will regularly update the map showing the devices current location. I have the following code:
private void UpdateMainLiveTileWithImage(Geopoint point, string city)
{
string ImageUrl = "http://maps.googleapis.com/maps/api/staticmap?maptype=satellite¢er=0,0&zoom=14&size=200x200&key=AIzaSyCX0fkuGP-bqLdtW67iHTU21Uiia_w5ULw";
string tileXmlString = "<tile>"
+ "<visual>"
+ "<binding template='TileSmall'>"
+ "<image src='" + ImageUrl + "' placement='background'/>"
+ "</binding>"
+ "<binding template='TileMedium'>"
+ "<image src='" + ImageUrl + "' placement='background'/>"
+ "</binding>"
+ "<binding template='TileWide'>"
+ "<image src='" + ImageUrl + "' placement='background'/>"
+ "</binding>"
+ "<binding template='TileLarge'>"
+ "<image src='" + ImageUrl + "' placement='background'/>"
+ "</binding>"
+ "</visual>"
+ "</tile>";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(tileXmlString);
TileNotification notifyTile = new TileNotification(xmlDoc);
TileUpdateManager.CreateTileUpdaterForApplication().Update(notifyTile);
}
On line xmlDoc.LoadXml(tileXmlString) I get the error:
An exception of type 'System.Exception' occurred in Trace.exe but was not handled in user code Additional information: Exception from HRESULT: 0xC00CE50D
I can use any other images from URLs such as https://www.google.co.uk/images/branding/googlelogo/2x/googlelogo_light_color_272x92dp.png. As far as I know I have met all of the conditions listed on the msdn website and from my understanding attempting to load an image that is to big ect would not cause an exception, the tile update would just be skipped.
I have tried using a variety of locations and sizes in the URL and have now stuck with the coordinates 0,0. This URL should work since it loads an image in browser and the msdn website says that PHP queries are a valid way of retrieving an image. Any help would be appreciated.
The problem here is the &
character in your image URL, you can fix this issue by using &
instead of &
. Because the tile payload is a XML document and &
is a pre-defined entity reference in XML, so we need use &
to escape it. Following is a valid tile payload:
<tile>
<visual>
<binding template='TileSmall'>
<image src='https://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=12&size=200x200&key=AIzaSyCX0fkuGP-bqLdtW67iHTU21Uiia_w5ULw' placement='background' />
</binding>
<binding template='TileMedium'>
<image src='https://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=12&size=200x200&key=AIzaSyCX0fkuGP-bqLdtW67iHTU21Uiia_w5ULw' placement='background' />
</binding>
<binding template='TileWide'>
<image src='https://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=12&size=200x200&key=AIzaSyCX0fkuGP-bqLdtW67iHTU21Uiia_w5ULw' placement='background' />
</binding>
<binding template='TileLarge'>
<image src='https://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=12&size=200x200&key=AIzaSyCX0fkuGP-bqLdtW67iHTU21Uiia_w5ULw' placement='background' />
</binding>
</visual>
</tile>