google-maps - 如何在 Windows Phone 8 应用程序中添加谷歌地图

标签 google-maps windows-phone-7 c#-4.0 windows-phone-8

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

我关注了一个链接
http://themightyhedgehog.blogspot.de/2013/01/how-to-use-google-maps-in-your-own.html
并尝试开发一个包含谷歌地图的应用程序。

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

  • Silverlight 不支持 BuildingHelpers。
  • 在“BuildingHelpers”类型中找不到可附加属性“TileSource”。
  • 未定义命名空间前缀“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();
            }
    
    
        }
    }
    

    最佳答案

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

    关于google-maps - 如何在 Windows Phone 8 应用程序中添加谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17894710/

    相关文章:

    javascript - 将鼠标悬停事件添加到 directionsRenderer Google Maps API v3

    c# - 在 WP7 中设置所选 ListPicker 值的文本

    c# - 从列表中获取数据以在代码中使用?

    php - PHP 中的哪些代码片段可以创建一个输入表单,从而在我的 mysql 数据库中创建一组新数据?

    android - Google map 问题上的自定义标记

    javascript - 需要同时在MAP上按多边形绘制美国各县

    windows-phone-7 - 如何将 wav 转换成 flac?

    c# - 标准方式为 Windows Phone 动态设置基于主题的图像

    c#-4.0 - 如何为快捷键实现键盘处理程序 cefSharp

    C# 4.0 - 如何处理可选的字符串参数