5

我正在开发一个使用 Windows Phone 8 地图服务的应用程序。

我点击链接 http://themightyhedgehog.blogspot.de/2013/01/how-to-use-google-maps-in-your-own.html 并尝试开发包含 Google Map 的应用程序。

但是我在 Xaml 中遇到了一个错误在线 MapAppScope:BindingHelpers.TileSource="{Binding GoogleMap}"

我得到的错误是:

  1. Silverlight 不支持 BuildingHelpers。
  2. 在“BuildingHelpers”类型中找不到可附加属性“TileSource”。
  3. 未定义命名空间前缀“MapAppScope”。

在 Xaml 中:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <Microsoft_Phone_Controls_Maps:Map 
Name="MyMap" 
Grid.Column="1" 
LogoVisibility="Collapsed" 
d:LayoutOverrides="GridBox" 
           MapAppScope:BindingHelpers.TileSource="{Binding GoogleMap}"
            Margin="0,0,0,2">
            <Microsoft_Phone_Controls_Maps:Map.Mode>
                <MSPCMCore:MercatorMode/>
            </Microsoft_Phone_Controls_Maps:Map.Mode>
        </Microsoft_Phone_Controls_Maps:Map>


    </Grid>

在 .CS 中:

    namespace Google_Map_App
{
    public enum GoogleType
    {
        Street = 'm',
        Hybrid = 'y',
        Satellite = 's',
        Physical = 't',
        PhysicalHybrid = 'p',
        StreetOverlay = 'h',
        WaterOverlay = 'r'
    }

    public class Google : TileSource
    {
        public Google()
        {
            MapType = GoogleType.Street;
            UriFormat = @"http://mt{0}.google.com/vt/lyrs={1}&z={2}&x={3}&y={4}";
        }

        public GoogleType MapType { get; set; }

        public override Uri GetUri(int x, int y, int zoomLevel)
        {
            return new Uri(
              string.Format(UriFormat, (x % 2) + (2 * (y % 2)),
              (char)MapType, zoomLevel, x, y));
        }
    }
    public static class BindingHelpers
    {
        //Used for binding a single TileSource object to a Bing Maps control
        #region TileSourceProperty

        // Name, Property type, type of object that hosts the property, method to call when anything changes
        public static readonly DependencyProperty TileSourceProperty =
            DependencyProperty.RegisterAttached("TileSource", typeof(TileSource),
            typeof(BindingHelpers), new PropertyMetadata(SetTileSourceCallback));

        // Called when TileSource is retrieved
        public static TileSource GetTileSource(DependencyObject obj)
        {
            return obj.GetValue(TileSourceProperty) as TileSource;
        }

        // Called when TileSource is set
        public static void SetTileSource(DependencyObject obj, TileSource value)
        {
            obj.SetValue(TileSourceProperty, value);
        }

        //Called when TileSource is set
        private static void SetTileSourceCallback(object sender, DependencyPropertyChangedEventArgs args)
        {

            var map = sender as Map;
            var newSource = args.NewValue as TileSource;
            if (newSource == null || map == null) return;

            // Remove existing layer(s)
            for (var i = map.Children.Count - 1; i >= 0; i--)
            {
                var tileLayer = map.Children[i] as MapTileLayer;
                if (tileLayer != null)
                {
                    map.Children.RemoveAt(i);
                }
            }

            var newLayer = new MapTileLayer();
            newLayer.TileSources.Add(newSource);
            map.Children.Add(newLayer);
        }

        #endregion
    }
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();
        }


    }
}
4

1 回答 1

1

请注意,在 Bing 地图 WP8 或 Windows 8 控件中使用 Google 地图图块违反了 Bing 地图和 Google 地图 API 的使用条款。在应用商店中找到的任何执行此操作的应用都将被删除。

于 2013-07-31T12:30:23.723 回答