C#桌面应用程序-使用Google Maps API计算两个城市之间的距离

时间:2018-10-01 05:50:11

标签: c# google-maps-api-3 google-distancematrix-api

我想创建一个Windows应用,使用Google Maps API计算两个城市之间的距离。

我可以使用下面的Javascript代码来处理此问题,但是,我不知道如何在Windows桌面应用中调用它。

1-)我可以在C#Windows应用程序中调用此javascript代码。 2)或者我该如何在C#Windows应用程序中编写相同的功能

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var origin = "The Mary Glowrey Building, 115 Victoria Parade, Fitzroy VIC 3065",
    destination = "building k level/1 St John St, Prahran VIC 3181",
    service = new google.maps.DistanceMatrixService();

service.getDistanceMatrix(
    {
        origins: [origin],
        destinations: [destination],
        travelMode: google.maps.TravelMode.DRIVING,
        avoidHighways: false,
        avoidTolls: false
    }, 
    callback
);

function callback(response, status) {
    var orig = document.getElementById("orig"),
        dest = document.getElementById("dest"),
        dist = document.getElementById("dist");

    if(status=="OK") {
        orig.value = response.destinationAddresses[0];
        dest.value = response.originAddresses[0];
        dist.value = response.rows[0].elements[0].distance.text;
    } else {
        alert("Error: " + status);
    }
}
</script>
</head>
<body>
    <br>
    Basic example for using the Distance Matrix.<br><br>
    Origin: <input id="orig" type="text" style="width:35em"><br><br>
    Destination: <input id="dest" type="text" style="width:35em"><br><br>
      Distance from Statue of Liberty to Washington DC, USA (by car): <input id="dist" type="text" style="width:35em">
</body>
</html>

0 个答案:

没有答案