我正在尝试使用下面的代码来计算两个位置之间的距离。
它可以显示正确的结果。
结果是FROM位置,TO位置和总里程。
我遇到的问题是
的价值 `<asp:Label ID="results" runat="server"></asp:Label>`
只需点击下一步按钮,就可以在名为vwPreviewData的多视图控件上预览一个名为vwPersonalData的多视图控件上的。
非常感谢任何帮助。
<script type="text/javascript">
var geocoder, location1, location2, gDir;
function initialize() {
geocoder = new GClientGeocoder();
gDir = new GDirections();
GEvent.addListener(gDir, "load", function () {
var drivingDistanceMiles = gDir.getDistance().meters / 1609.344;
var drivingDistanceKilometers = gDir.getDistance().meters / 1000;
document.getElementById("results").innerHTML = '<strong>From: </strong>' + location1.address + '<br /><strong>To: </strong>' + location2.address + '<br /><strong>Driving Distance: </strong>' + drivingDistanceMiles.toFixed(2) + ' miles ';
});
}
function showLocation() {
geocoder.getLocations(document.forms[0].address1.value, function (response) {
if (!response || response.Status.code != 200) {
alert("Sorry, we were unable to geocode the first address");
}
else {
location1 = { lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address };
geocoder.getLocations(document.forms[0].address2.value, function (response) {
if (!response || response.Status.code != 200) {
alert("Sorry, we were unable to geocode the second address");
}
else {
location2 = { lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address };
gDir.load('from: ' + location1.address + ' to: ' + location2.address);
}
});
}
});
}
</script>
// HTML
<asp:MultiView ID="myMultiView" ActiveViewIndex="0" runat="server">
<asp:View ID="vwPersonalData" runat="server">
<p>
<asp:TextBox ID="address1" runat="server" Text="Orlando, FL" ClientIDMode="Static"></asp:TextBox>
<asp:TextBox ID="address2" runat="server" Text="Birmingham, AL" ClientIDMode="Static"></asp:TextBox>
</p>
<asp:Label ID="results" runat="server" Text="" ClientIDMode="Static"></asp:Label>
</asp:View>
<asp:View ID="vwPreviewData" runat="server">
<asp:Label ID="lblPreviewresults" runat="server"></asp:Label>
</asp:view>
</asp:MultiView>
<asp:Button ID="btnNext" runat="server" Text="Next >" OnClientClick="showLocation(); return false;" OnClick="btnNext_Click" />