无法将谷歌地图 API 网址与 UWP 自适应磁贴模板结合使用



我有一个UWP,我正在其中编写一个可以跟踪设备位置的应用程序,最近我一直在尝试使用谷歌的静态地图API将地图的图像作为我的应用程序的实时平铺。其想法是,实时互动程序将定期更新显示设备当前位置的地图。我有以下代码:

private void UpdateMainLiveTileWithImage(Geopoint point, string city)
{
    string ImageUrl = "http://maps.googleapis.com/maps/api/staticmap?maptype=satellite&center=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);
}

在xmlDoc.LoadXml(tileXmlString)行上,我得到了错误:

Trace.exe中发生类型为"System.exception"的异常,但未在用户代码中处理附加信息:HRESULT:0xC00CE50D 出现异常

我可以使用URL中的任何其他图像,例如https://www.google.co.uk/images/branding/googlelogo/2x/googlelogo_light_color_272x92dp.png.据我所知,我已经满足了msdn网站上列出的所有条件,根据我的理解,尝试加载一个太大的图像不会导致异常,瓦片更新将被跳过。

我尝试过在URL中使用各种位置和大小,现在一直使用坐标0,0。这个URL应该可以工作,因为它在浏览器中加载图像,并且msdn网站说PHP查询是检索图像的有效方式。如有任何帮助,我们将不胜感激。

这里的问题是图像URL中的&字符,您可以使用&amp;而不是&来解决此问题。因为tile有效载荷是一个XML文档,而&是XML中预定义的实体引用,所以我们需要使用&amp;来转义它

<tile>
  <visual>
    <binding template='TileSmall'>
      <image src='https://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&amp;zoom=12&amp;size=200x200&amp;key=AIzaSyCX0fkuGP-bqLdtW67iHTU21Uiia_w5ULw' placement='background' />
    </binding>
    <binding template='TileMedium'>
      <image src='https://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&amp;zoom=12&amp;size=200x200&amp;key=AIzaSyCX0fkuGP-bqLdtW67iHTU21Uiia_w5ULw' placement='background' />
    </binding>
    <binding template='TileWide'>
      <image src='https://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&amp;zoom=12&amp;size=200x200&amp;key=AIzaSyCX0fkuGP-bqLdtW67iHTU21Uiia_w5ULw' placement='background' />
    </binding>
    <binding template='TileLarge'>
      <image src='https://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&amp;zoom=12&amp;size=200x200&amp;key=AIzaSyCX0fkuGP-bqLdtW67iHTU21Uiia_w5ULw' placement='background' />
    </binding>
  </visual>
</tile>

最新更新