public GDirectionResponse GetGRoute(GDirectionRequest request, bool alternatives) { var waypoints = "via:"; var first = true; if (request.WayPoints != null) { foreach (var point in request.WayPoints) { if (!first) { waypoints += "|"; } first = false; waypoints += point.Lat + "," + point.Lng; } } var directionResponse = new GDirectionResponse(); var client = new RestClient(directionApi); var restRequest = new RestRequest("json", Method.GET); restRequest.AddParameter("origin", request.Src.Lat + "," + request.Src.Lng); restRequest.AddParameter("destination", request.Dst.Lat + "," + request.Dst.Lng); restRequest.AddParameter("mode", "driving"); if (request.WayPoints != null && request.WayPoints.Count > 0) { restRequest.AddParameter("waypoints", waypoints); restRequest.AddParameter("waypoints", "optimize:true"); } if (alternatives) { restRequest.AddParameter("alternatives", "true"); } else { restRequest.AddParameter("alternatives", "false"); } restRequest.AddParameter("language", "fa"); IRestResponse response = client.Execute(restRequest); JavaScriptSerializer js = new JavaScriptSerializer(); if (!string.IsNullOrWhiteSpace(response.Content)) { directionResponse = js.Deserialize <GDirectionResponse>(response.Content); } return(directionResponse); }
public byte[] GetMapImage(GDirectionRequest request) { var client = new RestClient(staticMap); var restRequest = new RestRequest("staticmap", Method.GET); restRequest.AddParameter("size", "600x300"); restRequest.AddParameter("format", "JPEG"); restRequest.AddParameter("maptype", "roadmap"); restRequest.AddParameter("language", "fa"); var marker = "color:green|label:S|"; marker += request.Src.Lat + "," + request.Src.Lng + "|"; restRequest.AddParameter("markers", marker); marker = "color:green|label:D|"; marker += request.Dst.Lat + "," + request.Dst.Lng; restRequest.AddParameter("markers", marker); var path = "color:red|weight:5"; if (request.WayPoints != null && request.WayPoints.Count > 0) { foreach (var point in request.WayPoints) { path += "|"; path += point.Lat + "," + point.Lng; } } else { path += "|" + request.Src.Lat + "," + request.Src.Lng + "|" + request.Dst.Lat + "," + request.Dst.Lng; } restRequest.AddParameter("path", path); var res = client.DownloadData(restRequest); return(res); }