[英]Google direction API - How to pass Latitude and Longitude instead of Physical address
[英]how to dynamically pass multiple latitude and longitude to google distance matrix api in c#?
Below i've used hard coded multiple lat long var url = @"https://maps.googleapis.com/maps/api/distancematrix/xml?origins=24.74712999956982,46.5368152409792|24.5576972961426,46.8022346496582|24.9216365814209,46.7802574375|24.7977771759033,46.6214179992676 |24.6342353820801,46.5405044555664|24.869083404541,46.6235580444336|24.796724319458,46.7717247009277&destinations=24.7471295792982,46.5368152409792|24.5576972961426,46.8022346496582|24.9216365814209,46.7802734375|24.7977771759033,46.6214179992676|24.6342353820801,46.5405044555664|24.869083404541,46.6235580444336|24.796724319458,46.7717247009277&departure_time=1621784369&callback=InitializeMap&libraries=places&v=weekly ";
取决于你如何获取/存储这些坐标,真的。 一般来说, string.Join应该有帮助:
var origins = new double[][]
{
new [] {24.74712999956982, 46.5368152409792},
new [] {24.5576972961426, 46.8022346496582},
new [] {24.9216365814209, 46.7802574375},
new [] {24.7977771759033, 46.6214179992676},
new [] {24.6342353820801, 46.5405044555664},
new [] {24.869083404541, 46.6235580444336},
new [] {24.796724319458, 46.7717247009277},
};
var destinations = new double[][]
{
new [] {24.7471295792982, 46.5368152409792},
new [] {24.5576972961426, 46.8022346496582},
new [] {24.9216365814209, 46.7802734375},
new [] {24.7977771759033, 46.6214179992676},
new [] {24.6342353820801, 46.5405044555664},
new [] {24.869083404541, 46.6235580444336},
new [] {24.796724319458, 46.7717247009277},
};
string format(double[][] cords) => string.Join('|', cords.Select(c => string.Join(',', c)));
var output = $"https://maps.googleapis.com/maps/api/distancematrix/xml" +
$"?origins={format(origins)}" +
$"&destinations={format(destinations)}" +
$"&departure_time=1621784369" +
$"&callback=InitializeMap" +
$"&libraries=places" +
$"&v=weekly";
Console.WriteLine(output);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.