Support for Google maps

2 posts, 0 answers
  1. Peter
    Peter avatar
    28 posts
    Member since:
    Oct 2016

    Posted 14 Jun Link to this post

    One of our customers wants to be able to show Google maps in our application. I understand that they have purchased a licence to allow them to use the Goggle API. Has anyone tried to usethis with the RadMap control? Is it legal? Are Telerik planning any support for this?

    Thanks

    Pete

  2. Dinko
    Admin
    Dinko avatar
    416 posts

    Posted 19 Jun Link to this post

    Hello Peter,

    Thank you for contacting us.

    RadMap does not have a Google Maps provider and currently such cannot be implemented because of the additional protection which Google implemented in their service. Using the Google Maps tile server in a WPF application is not allowed. Currently, we do not plan to implement support for Google map API.

    In your case, you mentioned that the customer has a license for using Google API. In this case, you can try creating a custom Google provider. You can take a look at the Implement custom map provider help article in our documentation.Technically a custom Google Maps provider for RadMap can be designed like the sample code below.
    using System;
    using System.Collections.Generic;
    using System.Windows;
    using Telerik.Windows.Controls.Map;
      
    namespace GoogleMaps
    {
        public class GoogleCustomProvider : TiledProvider, ICloneable
        {
            /// <summary>
            /// Identifies the <see cref="Mode"/> Mode dependency property.
            /// </summary>
            public static readonly DependencyProperty ModeProperty = DependencyProperty.Register(
                "Mode",
                typeof(GoogleCustomMapMode),
                typeof(GoogleCustomProvider),
                new PropertyMetadata(ModeChanged));
      
            private ISpatialReference projection = new MercatorProjection();
            private Dictionary<GoogleCustomMapMode, string> mapModeSource = new Dictionary<GoogleCustomMapMode, string>();
      
            /// <summary>
            /// Initializes a new instance of the GoogleCustomProvider class.
            /// </summary>
            public GoogleCustomProvider()
                : base()
            {
                TiledMapSource source = new GoogleStreetCustomSource();
                this.MapSources.Add(source.UniqueId, source);
                this.mapModeSource[GoogleCustomMapMode.Street] = source.UniqueId;
      
                source = new GoogleSatelliteCustomSource();
                this.MapSources.Add(source.UniqueId, source);
                this.mapModeSource[GoogleCustomMapMode.Satellite] = source.UniqueId;
      
                source = new GoogleSatelliteHybridCustomSource();
                this.MapSources.Add(source.UniqueId, source);
                this.mapModeSource[GoogleCustomMapMode.SatelliteHybrid] = source.UniqueId;
      
                source = new GooglePhysicalCustomSource();
                this.MapSources.Add(source.UniqueId, source);
                this.mapModeSource[GoogleCustomMapMode.Physical] = source.UniqueId;
      
                source = new GooglePhysicalHybridCustomSource();
                this.MapSources.Add(source.UniqueId, source);
                this.mapModeSource[GoogleCustomMapMode.PhysicalHybrid] = source.UniqueId;
      
                this.SetupCommands();
            }
      
            /// <summary>
            /// Gets or sets map mode.
            /// </summary>
            public GoogleCustomMapMode Mode
            {
                get
                {
                    return (GoogleCustomMapMode)this.GetValue(ModeProperty);
                }
                set
                {
                    this.SetValue(ModeProperty, value);
                }
            }
      
            /// <summary>
            /// Returns the SpatialReference for the map provider.
            /// </summary>
            public override ISpatialReference SpatialReference
            {
                get
                {
                    return this.projection;
                }
            }
      
            public new object Clone()
            {
                GoogleCustomProvider clone = new GoogleCustomProvider();
                this.InheritCurrentSource(clone);
                this.InheritParameters(clone);
      
                return clone;
            }
      
            private static void ModeChanged(DependencyObject source, DependencyPropertyChangedEventArgs eventArgs)
            {
                GoogleCustomProvider provider = source as GoogleCustomProvider;
                if (provider != null)
                {
                    provider.OnMapModeChanged((GoogleCustomMapMode)eventArgs.OldValue, (GoogleCustomMapMode)eventArgs.NewValue);
                }
            }
      
            /// <summary>
            /// MapModeChanged handler.
            /// </summary>
            /// <param name="newMode">New map mode.</param>
            /// <param name="oldMode">Old map mode.</param>
            private void OnMapModeChanged(GoogleCustomMapMode oldMode, GoogleCustomMapMode newMode)
            {
                this.SetMapSource(this.mapModeSource[newMode]);
            }
      
            private void SetupCommands()
            {
                this.CommandBindingCollection.Clear();
      
                this.RegisterSetSourceCommand(
                    typeof(GoogleStreetCustomSource),
                    "Street",
                    null,
                    new Uri("/Telerik.Windows.Controls.DataVisualization;component/themes/road.png", UriKind.Relative),
                    null,
                    null);
      
                this.RegisterSetSourceCommand(
                    typeof(GoogleSatelliteCustomSource),
                    "Satellite",
                    null,
                    new Uri("/Telerik.Windows.Controls.DataVisualization;component/themes/aerial.png", UriKind.Relative),
                    null,
                    null);
      
      
                this.RegisterSetSourceCommand(
                    typeof(GoogleSatelliteHybridCustomSource),
                    "Satellite Hybrid",
                    null,
                    new Uri("/Telerik.Windows.Controls.DataVisualization;component/themes/aerial.png", UriKind.Relative),
                    null,
                    null);
      
                this.RegisterSetSourceCommand(
                    typeof(GooglePhysicalCustomSource),
                    "Physical",
                    null,
                    new Uri("/Telerik.Windows.Controls.DataVisualization;component/themes/aerial.png", UriKind.Relative),
                    null,
                    null);
      
                this.RegisterSetSourceCommand(
                    typeof(GooglePhysicalHybridCustomSource),
                    "Physical Hybrid",
                    null,
                    new Uri("/Telerik.Windows.Controls.DataVisualization;component/themes/aerial.png", UriKind.Relative),
                    null,
                    null);
            }
        }
      
        public class GoogleStreetCustomSource : GoogleCustomSourceBase
        {
            /// <summary>
            /// Initializes a new instance of the GoogleWorldImagerySource class.
            /// </summary>
            public GoogleStreetCustomSource()
                : base("m")
            {
            }
        }
      
        public class GoogleSatelliteCustomSource : GoogleCustomSourceBase
        {
            /// <summary>
            /// Initializes a new instance of the GoogleWorldImagerySource class.
            /// </summary>
            public GoogleSatelliteCustomSource()
                : base("s")
            {
            }
        }
      
        public class GoogleSatelliteHybridCustomSource : GoogleCustomSourceBase
        {
            /// <summary>
            /// Initializes a new instance of the GoogleWorldImagerySource class.
            /// </summary>
            public GoogleSatelliteHybridCustomSource()
                : base("y")
            {
            }
        }
      
        public class GooglePhysicalCustomSource : GoogleCustomSourceBase
        {
            /// <summary>
            /// Initializes a new instance of the GoogleWorldImagerySource class.
            /// </summary>
            public GooglePhysicalCustomSource()
                : base("t")
            {
            }
        }
      
        public class GooglePhysicalHybridCustomSource : GoogleCustomSourceBase
        {
            /// <summary>
            /// Initializes a new instance of the GoogleWorldImagerySource class.
            /// </summary>
            public GooglePhysicalHybridCustomSource()
                : base("p")
            {
            }
        }
      
        public class GoogleCustomSourceBase : TiledMapSource
        {
            private const string UrlFormat = @"http://mt{0}.google.com/vt/lyrs={1}&z={2}&x={3}&y={4}";
      
            private int server = 0;
            private string mapLayers;
      
            /// <summary>
            /// Initializes a new instance of the GoogleWorldMapSourceBase class.
            /// </summary>
            public GoogleCustomSourceBase(string mapLayers)
                : base(0, 19, 256, 256)
            {
                this.mapLayers = mapLayers;
            }
      
            /// <summary>
            /// Initialize provider.
            /// </summary>
            public override void Initialize()
            {
                // Raise provider initialized event.
                this.RaiseInitializeCompleted();
            }
      
            /// <summary>
            /// Gets the image URI.
            /// </summary>
            /// <param name="tileLevel">Tile level.</param>
            /// <param name="tilePositionX">Tile X.</param>
            /// <param name="tilePositionY">Tile Y.</param>
            /// <returns>URI of image.</returns>
            protected override Uri GetTile(int tileLevel, int tilePositionX, int tilePositionY)
            {
                int zoomLevel = ConvertTileToZoomLevel(tileLevel);
      
                string url = string.Empty;
                string prefix = string.Empty;
      
                this.server = (this.server + 1) % 4;
      
                url = string.Format(UrlFormat, server, this.mapLayers, zoomLevel, tilePositionX, tilePositionY);
                url = ProtocolHelper.SetScheme(url);
      
                return new Uri(url);
            }
        }
      
        /// <summary>
        /// Represents map modes.
        /// </summary>
        public enum GoogleCustomMapMode
        {
            Street,
            Satellite,
            SatelliteHybrid,
            Physical,
            PhysicalHybrid
        }
    }
    <telerik:RadMap x:Name="radMap">
        <telerik:RadMap.Provider>
            <local:GoogleCustomProvider Mode="SatelliteHybrid" />
        </telerik:RadMap.Provider>
    </telerik:RadMap>

    Regards,
    Dinko
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Back to Top