C
C#4h ago
Yarden

I want to use "Route matrix" with C# backend. How do I know the structure?

I was reading Google website about "Get a route matrix" and how to use this api. Now, the JSON structure is totally different compared to C#, so I failed to use it. I used chatGPT and it created the right structure in seconds, but the thing is that I want to learn how to build the structure by my self. what GPT gave is:
var body = new
{
origins = new[]
{
new { waypoint = new { location = new { latLng = new { latitude = 37.420761, longitude = -122.081356 } } } },
new { waypoint = new { location = new { latLng = new { latitude = 37.403184, longitude = -122.097371 }}}}
},
destinations = new[]
{
new { waypoint = new { location = new { latLng = new { latitude = 37.420999, longitude = -122.086894 } } } },
new { waypoint = new { location = new { latLng = new { latitude = 37.383047, longitude = -122.044651 } } } }
},
travelMode = "DRIVE"
};

var resp = await http.PostAsJsonAsync("distanceMatrix/v2:computeRouteMatrix", body);
var text = await resp.Content.ReadAsStringAsync();
// The API streams one JSON object per line (NDJSON). Returning as text or application/json is fine.
return Content(text, "application/json");
}
var body = new
{
origins = new[]
{
new { waypoint = new { location = new { latLng = new { latitude = 37.420761, longitude = -122.081356 } } } },
new { waypoint = new { location = new { latLng = new { latitude = 37.403184, longitude = -122.097371 }}}}
},
destinations = new[]
{
new { waypoint = new { location = new { latLng = new { latitude = 37.420999, longitude = -122.086894 } } } },
new { waypoint = new { location = new { latLng = new { latitude = 37.383047, longitude = -122.044651 } } } }
},
travelMode = "DRIVE"
};

var resp = await http.PostAsJsonAsync("distanceMatrix/v2:computeRouteMatrix", body);
var text = await resp.Content.ReadAsStringAsync();
// The API streams one JSON object per line (NDJSON). Returning as text or application/json is fine.
return Content(text, "application/json");
}
And in the website you can see the JSON structure is totally different: https://developers.google.com/maps/documentation/routes/compute_route_matrix How do I learn how to convert from google's structure to C#? I didn't find articles\videos about it
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?