TorbenK / TK.CustomMap

Extended Map Control
MIT License
142 stars 109 forks source link

Is it possible to change language retrieved from route's instruction #222

Open vincentcastagna opened 7 years ago

vincentcastagna commented 7 years ago

Hello,

I have sucessfully implemented routes and getting instructions well ... but I need to display instructions in French ? Is it possible to change instructions language retrieved from API ?

Thanks

TorbenK commented 7 years ago

What language is your device on?

vincentcastagna commented 7 years ago

Its in French. But oddly it retrieves me instruction in English.

I'm in debug ... perhaps something to do with that ? I'll try to deploy on playstore to see if I still have the prob

vincentcastagna commented 7 years ago

Any ideas ?

TorbenK commented 7 years ago

Sorry. So it seems not be possible right now. I have to investigate this.

vincentcastagna commented 7 years ago

Your package is using that, isn't it ? https://developers.google.com/maps/documentation/directions/intro?hl=en

So I guess that we can have some clues : "If language is not supplied, the API attempts to use the preferred language as specified in the Accept-Language header, or the native language of the domain from which the request is sent"

TorbenK commented 7 years ago

It depends on what you are using. If you takling about Android and the native API, I indeed use the directions API.

On iOS: https://developer.apple.com/reference/mapkit/mkdirections

vincentcastagna commented 7 years ago

Yep sorry did not gave the context.

Well, could it be possible to add some parameters to the TKroute like language preference to pass to the android native API ? I'll try to see if I have time (not sure) to make a PR about this if you think that will be difficult to handle this on your time (and actual contributors)

TorbenK commented 7 years ago

If this is possible on all platforms, we could do it. If some platforms behave different, for instance if they always use the device language setting, we should not add it into TKRoute.

Micnick commented 7 years ago

Hi, guys on what propertie I found the instrucctions? tanks

vincentcastagna commented 7 years ago

@Micnick Check the sample. Everything you need is in TKRoute.

  foreach (var s in route.Steps)
            {
                this.Instructions.Html += string.Format("<b>{0}km:</b> {1}<br /><hr />", s.Distance / 1000,
                    s.Instructions);
            }

@TorbenK Nothing new about this ?

Micnick commented 7 years ago

@Umar3x TAnks

the route.Steps propertie is null, how to fill them?

vincentcastagna commented 7 years ago

Hello,

@TorbenK have you got any news concerning this demand ? Thanks

vincentcastagna commented 7 years ago

The option is just missing in TKCustomMapRenderer, function AddRoute for routeData.

  /// <summary>
        /// Calculates and adds the route to the map
        /// </summary>
        /// <param name="route">The route to add</param>
        private async void AddRoute(TKRoute route)
        {
            if (route == null) return;

            this._tempRouteList.Add(route);

            route.PropertyChanged += OnRoutePropertyChanged;

            GmsDirectionResult routeData = null;
            string errorMessage = null;

            routeData = await GmsDirection.Instance.CalculateRoute(route.Source, route.Destination, route.TravelMode.ToGmsTravelMode(), HERE );

Which could give the optional parameter language present in the GmsDirection.cs

   /// <summary>
        /// Calculates a route
        /// </summary>
        /// <param name="origin">The origin</param>
        /// <param name="destination">The destination</param>
        /// <param name="mode">The travelling mode</param>
        /// <param name="language">The language</param>
        /// <returns>A <see cref="GmsDirectionResult"/></returns>
        public async Task<GmsDirectionResult> CalculateRoute(Position origin, Position destination, GmsDirectionTravelMode mode, string language = null)
        {
            var response = await _httpClient.GetAsync(this.BuildQueryString(origin, destination, mode, language));

            if (response.IsSuccessStatusCode)
            {
                return JsonConvert.DeserializeObject<GmsDirectionResult>(await response.Content.ReadAsStringAsync());
            }
            return null;
        }

I'm going to do a PR about this. When is the next release planned ? Thanks.