I'm using the code found here to calculate the distance between places.
Here's the fiddle and the code:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
origin = new google.maps.LatLng(40.689844,-74.044874),
destination = "Washington, DC",
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) {
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>
Destination: <input id="dest" type="text" style="width:35em"><br>
Distance from Statue of Liberty to Washington DC, USA (by car): <input id="dist" type="text" style="width:35em"><br>
</body>
</html>
Everything works fine, but I'd like to change input tags with div tags. However, if I change "input id" do "div id", it doesn't work:
Origin: <div id="orig" type="text" style="width:35em"></div>
Destination: <div id="dest" type="text" style="width:35em"></div>
Distance from Statue of Liberty to Washington DC, USA (by car): <div id="dist" type="text" style="width:35em"></div>
Shouldn't it be irrelevant if it's a div, input, span or whatever, as long as it has that id? What should be changed to output the results in a div? Thank you.