aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Providers/PlacesProvider.cs
blob: 681815d4c73f56342524f40eb6d37b4a99006e59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highl
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Tango.AutoComplete.Editors;
using Tango.Logging;

namespace Tango.MachineStudio.UsersAndRoles.Providers
{
    public class PlacesProvider : ISuggestionProvider
    {
        public IEnumerable GetSuggestions(string filter)
        {
            List<Place> places = new List<Place>();

            using (WebClient web = new WebClient())
            {
                try
                {
                    String json = null;

                    web.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0");
                    web.Headers.Add(HttpRequestHeader.ContentType, "application/json");
                    web.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-US");

                    json = web.DownloadString(String.Format("https://nominatim.openstreetmap.org/search?q={0}&format=json&addressdetails=1", filter));

                    if (json != null)
                    {
                        List<Place> results = JsonConvert.DeserializeObject<List<Place>>(json);
                        places.AddRange(results);
                    }
                }
                catch (Exception ex)
                {
                    LogManager.Default.Log(ex, LogCategory.Debug);
                }
            }

            return places;
        }
    }
}