added first steps for autosuggest API
This commit is contained in:
Родитель
1a6cf4caf1
Коммит
2f024b5992
|
@ -131,7 +131,6 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Enums\" />
|
|
||||||
<Folder Include="Extensions\TSP Resources\" />
|
<Folder Include="Extensions\TSP Resources\" />
|
||||||
<Folder Include="Models\CustomMapStyles\" />
|
<Folder Include="Models\CustomMapStyles\" />
|
||||||
<Folder Include="Models\ResponseModels\" />
|
<Folder Include="Models\ResponseModels\" />
|
||||||
|
|
|
@ -39,6 +39,8 @@
|
||||||
<SignAssembly>false</SignAssembly>
|
<SignAssembly>false</SignAssembly>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Enums\AutosuggestEntityType.cs" />
|
||||||
|
<Compile Include="Enums\AutosuggestLocationType.cs" />
|
||||||
<Compile Include="Enums\AvoidType.cs" />
|
<Compile Include="Enums\AvoidType.cs" />
|
||||||
<Compile Include="Enums\ConfidenceLevelType.cs" />
|
<Compile Include="Enums\ConfidenceLevelType.cs" />
|
||||||
<Compile Include="Enums\DimensionUnitType.cs" />
|
<Compile Include="Enums\DimensionUnitType.cs" />
|
||||||
|
@ -119,10 +121,12 @@
|
||||||
<Compile Include="Models\ResponseModels\StaticMapMetadata.cs" />
|
<Compile Include="Models\ResponseModels\StaticMapMetadata.cs" />
|
||||||
<Compile Include="Models\ResponseModels\TrafficIncident.cs" />
|
<Compile Include="Models\ResponseModels\TrafficIncident.cs" />
|
||||||
<Compile Include="Models\ResponseModels\TransitLine.cs" />
|
<Compile Include="Models\ResponseModels\TransitLine.cs" />
|
||||||
|
<Compile Include="Models\CircularView.cs" />
|
||||||
<Compile Include="Models\ResponseModels\Warning.cs" />
|
<Compile Include="Models\ResponseModels\Warning.cs" />
|
||||||
<Compile Include="Models\ResponseModels\Waypoint.cs" />
|
<Compile Include="Models\ResponseModels\Waypoint.cs" />
|
||||||
<Compile Include="Models\RouteOptions.cs" />
|
<Compile Include="Models\RouteOptions.cs" />
|
||||||
<Compile Include="Models\VehicleSpec.cs" />
|
<Compile Include="Models\VehicleSpec.cs" />
|
||||||
|
<Compile Include="Requests\AutosuggestRequest.cs" />
|
||||||
<Compile Include="Requests\DistanceMatrixRequest.cs" />
|
<Compile Include="Requests\DistanceMatrixRequest.cs" />
|
||||||
<Compile Include="Requests\GeospatialEndpointRequest.cs" />
|
<Compile Include="Requests\GeospatialEndpointRequest.cs" />
|
||||||
<Compile Include="Requests\ImageryMetadataRequest.cs" />
|
<Compile Include="Requests\ImageryMetadataRequest.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
|
||||||
|
}
|
||||||
|
}
|
|
@ -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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Enum for the Type of Location/Region used in REST Autosuggest Calls
|
||||||
|
/// </summary>
|
||||||
|
public enum AutosuggestLocationType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Use a user location and confidence number
|
||||||
|
/// </summary>
|
||||||
|
userLocation,
|
||||||
|
/// <summary>
|
||||||
|
/// Use a Circular Region: central point plus radius
|
||||||
|
/// </summary>
|
||||||
|
userCircularMapView,
|
||||||
|
/// <summary>
|
||||||
|
/// Use a Bounding Box Region
|
||||||
|
/// </summary>
|
||||||
|
userMapView
|
||||||
|
}
|
||||||
|
}
|
|
@ -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; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Radius (Meters)
|
||||||
|
/// </summary>
|
||||||
|
public int radius { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<Enums.AutosuggestEntityType>()
|
||||||
|
{
|
||||||
|
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<BingMapsRESTToolkit.Enums.AutosuggestEntityType> IncludeEntityTypes {get; set;}
|
||||||
|
|
||||||
|
public BingMapsRESTToolkit.Enums.AutosuggestLocationType AutoLocation { get; set; }
|
||||||
|
|
||||||
|
public string query { get; set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public override Task<Response> Execute()
|
||||||
|
{
|
||||||
|
return this.Execute(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<Response> Execute(Action<int> remainingTimeCallback)
|
||||||
|
{
|
||||||
|
Stream responseStream = null;
|
||||||
|
|
||||||
|
responseStream = await ServiceHelper.GetStreamAsync(new Uri(GetRequestUrl()));
|
||||||
|
|
||||||
|
|
||||||
|
if (responseStream != null)
|
||||||
|
{
|
||||||
|
var r = ServiceHelper.DeserializeStream<Response>(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<string> param_list = new List<string>
|
||||||
|
{
|
||||||
|
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<string> vals = new List<string>();
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -56,6 +56,11 @@ namespace BingMapsRESTToolkit
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public BoundingBox UserMapView { get; set; }
|
public BoundingBox UserMapView { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The circular geographic region that corresponds to the current viewport.
|
||||||
|
/// </summary>
|
||||||
|
public CircularView UserCircularMapView {get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The user’s current position.
|
/// The user’s current position.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Загрузка…
Ссылка в новой задаче