diff --git a/Source/BingMapsRESTToolkit.Standard/BingMapsRESTToolkit.Standard.csproj b/Source/BingMapsRESTToolkit.Standard/BingMapsRESTToolkit.Standard.csproj index 9fd21d4..1cfc5c1 100644 --- a/Source/BingMapsRESTToolkit.Standard/BingMapsRESTToolkit.Standard.csproj +++ b/Source/BingMapsRESTToolkit.Standard/BingMapsRESTToolkit.Standard.csproj @@ -131,7 +131,6 @@ - diff --git a/Source/BingMapsRESTToolkit.csproj b/Source/BingMapsRESTToolkit.csproj index a62ddfb..2c0751f 100644 --- a/Source/BingMapsRESTToolkit.csproj +++ b/Source/BingMapsRESTToolkit.csproj @@ -39,6 +39,8 @@ false + + @@ -119,10 +121,12 @@ + + diff --git a/Source/Enums/AutosuggestEntityType.cs b/Source/Enums/AutosuggestEntityType.cs new file mode 100644 index 0000000..931777f --- /dev/null +++ b/Source/Enums/AutosuggestEntityType.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BingMapsRESTToolkit.Enums +{ + public enum AutosuggestEntityType + { + Address, + Place, + LocalBusiness + } +} diff --git a/Source/Enums/AutosuggestLocationtype.cs b/Source/Enums/AutosuggestLocationtype.cs new file mode 100644 index 0000000..6b410ea --- /dev/null +++ b/Source/Enums/AutosuggestLocationtype.cs @@ -0,0 +1,51 @@ +/* + * Copyright(c) 2018 Microsoft Corporation. All rights reserved. + * + * This code is licensed under the MIT License (MIT). + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. +*/ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BingMapsRESTToolkit.Enums +{ + /// + /// Enum for the Type of Location/Region used in REST Autosuggest Calls + /// + public enum AutosuggestLocationType + { + /// + /// Use a user location and confidence number + /// + userLocation, + /// + /// Use a Circular Region: central point plus radius + /// + userCircularMapView, + /// + /// Use a Bounding Box Region + /// + userMapView + } +} diff --git a/Source/Models/CircularView.cs b/Source/Models/CircularView.cs new file mode 100644 index 0000000..a4eb058 --- /dev/null +++ b/Source/Models/CircularView.cs @@ -0,0 +1,62 @@ +/* + * Copyright(c) 2018 Microsoft Corporation. All rights reserved. + * + * This code is licensed under the MIT License (MIT). + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. +*/ + +using System.Globalization; +using System.Runtime.Serialization; + + +namespace BingMapsRESTToolkit +{ + [DataContract] + public class CircularView + { + CircularView() + { + } + + CircularView(float latitude, float longitude, int radius) + { + if (radius >= 0) + this.radius = radius; + else + throw new System.Exception("Radius in UserCircularMapView Constructor must be greater than 0"); + + this.coords.Latitude = latitude; + this.coords.Longitude = longitude; + } + + public override string ToString() + { + return string.Format(CultureInfo.InvariantCulture, "{0:0.#####},{1:0.#####},{2}", coords.Latitude, coords.Longitude, radius); + } + + public Coordinate coords { get; set; } + + /// + /// Radius (Meters) + /// + public int radius { get; set; } + + } +} diff --git a/Source/Requests/AutosuggestRequest.cs b/Source/Requests/AutosuggestRequest.cs new file mode 100644 index 0000000..02e5330 --- /dev/null +++ b/Source/Requests/AutosuggestRequest.cs @@ -0,0 +1,146 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.IO; +using System.Text; +using System.Threading.Tasks; + +namespace BingMapsRESTToolkit.Requests +{ + class AutosuggestRequest : BaseRestRequest + { + + #region Private Properties + private const int max_maxResults = 10; + + #endregion + + #region Constructor + + public AutosuggestRequest() + { + this.AutoLocation = Enums.AutosuggestLocationType.userLocation; + this.IncludeEntityTypes = new List() + { + BingMapsRESTToolkit.Enums.AutosuggestEntityType.Address, + BingMapsRESTToolkit.Enums.AutosuggestEntityType.LocalBusiness, + BingMapsRESTToolkit.Enums.AutosuggestEntityType.Place, + }; + this.Culture = "en-US"; + this.UserRegion = "US"; + this.CountryFilter = null; + this.query = ""; + + } + + #endregion + + #region Public Properties + + public Coordinate UserLocation { get; set; } + + public string UserRegion { get; set; } + + public String CountryFilter { get; set; } + + public List IncludeEntityTypes {get; set;} + + public BingMapsRESTToolkit.Enums.AutosuggestLocationType AutoLocation { get; set; } + + public string query { get; set; } + + #endregion + + #region Public Methods + + public override Task Execute() + { + return this.Execute(null); + } + + public override async Task Execute(Action remainingTimeCallback) + { + Stream responseStream = null; + + responseStream = await ServiceHelper.GetStreamAsync(new Uri(GetRequestUrl())); + + + if (responseStream != null) + { + var r = ServiceHelper.DeserializeStream(responseStream); + responseStream.Dispose(); + return r; + } + + return null; + } + + public override string GetRequestUrl() + { + if (this.query == "") + throw new Exception("Empty Query in Autosuggest REST Request"); + + string queryStr = string.Format("q={0}", this.query); + + string locStr = null; + + switch(AutoLocation) + { + case Enums.AutosuggestLocationType.userCircularMapView: + locStr = string.Format("ucmv={0}", this.UserCircularMapView.ToString()); + break; + case Enums.AutosuggestLocationType.userMapView: + locStr = string.Format("umv={0}", this.UserMapView.ToString()); + break; + case Enums.AutosuggestLocationType.userLocation: + locStr = string.Format("ul={0}", this.UserLocation.ToString()); + break; + } + + string inclEntityStr = string.Format("inclenttype={0}", getIncludeEntityTypeString()); + + string cultureStr = string.Format("c={0}", Culture.ToString()); + + List param_list = new List + { + queryStr, + locStr, + inclEntityStr, + cultureStr, + string.Format("key={0}", BingMapsKey) + }; + + return this.Domain + "Autosuggest?" + string.Join("&", param_list); + } + + #endregion + + #region Private Methods + + private string getIncludeEntityTypeString() + { + List vals = new List(); + + foreach(var entity_type in IncludeEntityTypes.Distinct()) + { + switch(entity_type) + { + case Enums.AutosuggestEntityType.Address: + vals.Add("Address"); + break; + case Enums.AutosuggestEntityType.LocalBusiness: + vals.Add("Business"); + break; + case Enums.AutosuggestEntityType.Place: + vals.Add("Place"); + break; + } + } + + return string.Join(",", vals); + } + + #endregion + + } +} diff --git a/Source/Requests/BaseRestRequest.cs b/Source/Requests/BaseRestRequest.cs index 5043080..914f257 100644 --- a/Source/Requests/BaseRestRequest.cs +++ b/Source/Requests/BaseRestRequest.cs @@ -56,6 +56,11 @@ namespace BingMapsRESTToolkit /// public BoundingBox UserMapView { get; set; } + /// + /// The circular geographic region that corresponds to the current viewport. + /// + public CircularView UserCircularMapView {get; set; } + /// /// The user’s current position. ///