У меня есть метод ниже,
[IdentityBasicAuthentication]
[Authorize]
public HttpResponseMessage PostRouteInformation(RouteCreateInformationMM routeCreateInformation)
{
try
{
return Request.CreateResponse(HttpStatusCode.OK, _routeMobileManager.RetreiveCreateRouteInformation(routeCreateInformation));
}
catch (BusinessException bex)
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, bex.Message);
}
}
Что он делает, он создает URL с заданными значениями широты и логитивности и публикует его в Googleapis.После этого он захватывает возвращенную строку JSON и заполняет необходимые поля из этой возвращенной строки JSON.
Ниже приведен метод, о котором я говорю выше,
public string GetRouteInformation(RouteCreateInformationMM routeCreateInformation, List<MapOriginsMM> poiCoordinates)
{
string url = GetRouteUrl(routeCreateInformation, poiCoordinates);
WebClient webClient = new WebClient();
var content = webClient.DownloadString(url);
return content;
}
А ниже приведен методтот, который создает строку URL,
private string GetRouteUrl(RouteCreateInformationMM routeCreateInformation, List<MapOriginsMM> poiCoordinates)
{
StringBuilder sb = new StringBuilder();
sb.Append(ConstantValue.StaticMap.RouteInformationUrl);
sb.Append("?mode=");
sb.Append(routeCreateInformation.Mode);
if (routeCreateInformation.Latitude != 0 && routeCreateInformation.Longitude != 0)
{
sb.Append("&origin=");
sb.Append(routeCreateInformation.Latitude.ToString(System.Globalization.CultureInfo.InvariantCulture) + "," + routeCreateInformation.Longitude.ToString(System.Globalization.CultureInfo.InvariantCulture));
foreach (var origins in poiCoordinates)
{
if (origins == poiCoordinates.Last())
{
sb.Append("&destination=");
sb.Append(origins.Latitude.ToString(System.Globalization.CultureInfo.InvariantCulture) + "," + origins.Longitude.ToString(System.Globalization.CultureInfo.InvariantCulture));
}
}
}
else
{
foreach (var origins in poiCoordinates)
{
if (origins == poiCoordinates.First())
{
sb.Append("&origin=");
sb.Append(origins.Latitude.ToString(System.Globalization.CultureInfo.InvariantCulture) + "," + origins.Longitude.ToString(System.Globalization.CultureInfo.InvariantCulture));
}
else if (origins == poiCoordinates.Last())
{
sb.Append("&destination=");
sb.Append(origins.Latitude.ToString(System.Globalization.CultureInfo.InvariantCulture) + "," + origins.Longitude.ToString(System.Globalization.CultureInfo.InvariantCulture));
}
}
}
foreach (var origins in poiCoordinates)
{
if (origins != poiCoordinates.First() && origins != poiCoordinates.Last())
{
sb.Append("&waypoints=optimize:true|" + origins.Latitude.ToString(System.Globalization.CultureInfo.InvariantCulture) + "," + origins.Longitude.ToString(System.Globalization.CultureInfo.InvariantCulture));
}
}
sb.Append($"&key={ConstantValue.ApiKey}");
return sb.ToString();
}
В конце URL выглядит примерно так (кстати, я намеренно составил значение ключа для вопроса):
https://maps.googleapis.com/maps/api/directions/json?mode=walking&origin=41.0923621,29.0947456&destination=41.0943909,29.0966665&key=AOzaSyApOqYW39erJ7zWsqXnV-0NLfltkHu0KfB
И то, что он возвращает, это:
{"geocoded_waypoints" : [
{
"geocoder_status" : "OK",
"place_id" : "ChIJNXFeZrXLyhQR96lj9-GkDP4",
"types" : [ "street_address" ]
},
{
"geocoder_status" : "OK",
"place_id" : "ChIJv29FSLTLyhQR2bYQoTP2p6Y",
"types" : [
"bus_station",
"establishment",
"point_of_interest",
"transit_station"
]
}],"routes" : [
{
"bounds" : {
"northeast" : {
"lat" : 41.0946222,
"lng" : 29.0967187
},
"southwest" : {
"lat" : 41.0916837,
"lng" : 29.0938952
}
},
"copyrights" : "Harita verileri ©2019 Google",
"legs" : [
{
"distance" : {
"text" : "0,6 km",
"value" : 646
},
"duration" : {
"text" : "9 dakika",
"value" : 523
},
"end_address" : "Rüzgarlı Bahçe Mahallesi, Sedir Sokak, Sedir Sokak, 34805 Beykoz/İstanbul, Türkiye",
"end_location" : {
"lat" : 41.09436549999999,
"lng" : 29.0967187
},
"start_address" : "Kavacık Mahallesi, Ertürk Sk. No:3, 34810 Beykoz/İstanbul, Türkiye",
"start_location" : {
"lat" : 41.092368,
"lng" : 29.0947267
},
"steps" : [
{
"distance" : {
"text" : "0,1 km",
"value" : 128
},
"duration" : {
"text" : "2 dakika",
"value" : 95
},
"end_location" : {
"lat" : 41.0917854,
"lng" : 29.0938952
},
"html_instructions" : "\u003cb\u003eMuhtar Sk.\u003c/b\u003e adlı yerden \u003cb\u003egüney\u003c/b\u003e yönünde ilerleyin",
"polyline" : {
"points" : "izxyFaqqpDb@R|At@B@@@?@?@@??@?DUjA"
},
"start_location" : {
"lat" : 41.092368,
"lng" : 29.0947267
},
"travel_mode" : "WALKING"
},
{
"distance" : {
"text" : "0,1 km",
"value" : 131
},
"duration" : {
"text" : "2 dakika",
"value" : 101
},
"end_location" : {
"lat" : 41.0927256,
"lng" : 29.0943774
},
"html_instructions" : "\u003cb\u003eMuhtar Sk.\u003c/b\u003e boyunca ilerlemek için \u003cb\u003esağa\u003c/b\u003e dönün",
"maneuver" : "turn-right",
"polyline" : {
"points" : "uvxyF{kqpDECIGQQiAcAOOIIECEAC?E?E@CBGFCFIJ"
},
"start_location" : {
"lat" : 41.0917854,
"lng" : 29.0938952
},
"travel_mode" : "WALKING"
},
{
"distance" : {
"text" : "69 m",
"value" : 69
},
"duration" : {
"text" : "1 dakika",
"value" : 54
},
"end_location" : {
"lat" : 41.0931956,
"lng" : 29.094848
},
"html_instructions" : "\u003cb\u003eErtürk Sk.\u003c/b\u003e yönünde \u003cb\u003esağa\u003c/b\u003e dönün",
"maneuver" : "turn-right",
"polyline" : {
"points" : "q|xyF{nqpDEGUYMMQQGIECCCECIE"
},
"start_location" : {
"lat" : 41.0927256,
"lng" : 29.0943774
},
"travel_mode" : "WALKING"
},
{
"distance" : {
"text" : "0,2 km",
"value" : 159
},
"duration" : {
"text" : "2 dakika",
"value" : 118
},
"end_location" : {
"lat" : 41.09448829999999,
"lng" : 29.0952805
},
"html_instructions" : "\u003cb\u003eEkinciler Cd.\u003c/b\u003e yönünde devam edin",
"polyline" : {
"points" : "o_yyFyqqpDGIOSIKIMOOMOKMECEEIEIGCAGAKCE?E?G?K@EBi@PWHBPMBAG"
},
"start_location" : {
"lat" : 41.0931956,
"lng" : 29.094848
},
"travel_mode" : "WALKING"
},
{
"distance" : {
"text" : "17 m",
"value" : 17
},
"duration" : {
"text" : "1 dakika",
"value" : 24
},
"end_location" : {
"lat" : 41.0945246,
"lng" : 29.0954362
},
"html_instructions" : "\u003cb\u003eCumhuriyet Cd.\u003c/b\u003e yönünde \u003cb\u003esağa\u003c/b\u003e dönün",
"maneuver" : "turn-right",
"polyline" : {
"points" : "qgyyFotqpDCMAQ"
},
"start_location" : {
"lat" : 41.09448829999999,
"lng" : 29.0952805
},
"travel_mode" : "WALKING"
},
{
"distance" : {
"text" : "9 m",
"value" : 9
},
"duration" : {
"text" : "1 dakika",
"value" : 6
},
"end_location" : {
"lat" : 41.0945706,
"lng" : 29.0955857
},
"html_instructions" : "\u003cb\u003eCumhuriyet Cd.\u003c/b\u003e boyunca ilerlemek için \u003cb\u003esola\u003c/b\u003e dönün",
"maneuver" : "turn-left",
"polyline" : {
"points" : "wgyyFouqpDC?OKHQ"
},
"start_location" : {
"lat" : 41.0945246,
"lng" : 29.0954362
},
"travel_mode" : "WALKING"
},
{
"distance" : {
"text" : "0,1 km",
"value" : 133
},
"duration" : {
"text" : "2 dakika",
"value" : 125
},
"end_location" : {
"lat" : 41.09436549999999,
"lng" : 29.0967187
},
"html_instructions" : "\u003cb\u003eCumhuriyet Cd.\u003c/b\u003e boyunca ilerlemek için \u003cb\u003esağa\u003c/b\u003e dönün",
"maneuver" : "turn-right",
"polyline" : {
"points" : "ahyyFmvqpDBCBIDMPBNGRIBSAG?K@E?CBGDUDQFOEIYe@MMIG"
},
"start_location" : {
"lat" : 41.0945706,
"lng" : 29.0955857
},
"travel_mode" : "WALKING"
}
],
"traffic_speed_entry" : [],
"via_waypoint" : []
}
],
"overview_polyline" : {
"points" : "izxyFaqqpDfClA@DUpAOKuBoBKEI?IDKNIJEGc@g@c@c@OIW]q@y@a@]MISE_@@o@TWHBPMBAGE_@SKLUHWPBNGRIBSASJg@La@_@o@WU"
},
"summary" : "Muhtar Sk.",
"warnings" : [
"Yürüyerek gitmek için yol tarifi beta özelliğinde mevcuttur. Dikkat – Bu rotada kaldırım veya yaya yolu olmayabilir."
],
"waypoint_order" : []
}],"status" : "OK"}
Все в порядке, пока я не опубликую свой проект и не помещу его в наш тестовый домен.
Я мог бы успешно заполнить свою модель возврата, ЕСЛИ я работаюна моем локальном хосте
[{"Legs":[{"Steps":[{"EndLocation":[{"Lat":41.0917854,"Lng":29.0938952},{"Lat":41.0927256,"Lng":29.0943774},{"Lat":41.0931956,"Lng":29.094848},{"Lat":41.094488299999988,"Lng":29.0952805},{"Lat":41.0945246,"Lng":29.0954362},{"Lat":41.0945706,"Lng":29.0955857},{"Lat":41.094365499999988,"Lng":29.0967187}]}]}]}]
Но, если я отправляю запрос в живой проект, он возвращает мне нулевую модель,
[{"Legs":[{"Steps":[{"EndLocation":[]}]}]}]
Я понятия не имею, почему.Может ли это быть что-то с родственными Googleapis?Или, может быть, WebClient
не работает должным образом на сервере.
Заранее спасибо!