<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true"></script> <script type="text/javascript"> var map; function initialize() { // Try HTML5 geolocation if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function (position) { var pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); document.getElementById('<%= Label1.ClientID %>').innerHTML = pos; calcRoute(); }, function () { handleNoGeolocation(true); }); } else { // Browser doesn't support Geolocation handleNoGeolocation(false); } } function handleNoGeolocation(errorFlag) { if (errorFlag) { var content = 'Error: The Geolocation service failed.'; } else { var content = 'Error: Your browser doesn\'t support geolocation.'; //' //[edit] fixing code color } } function calcRoute() { var start = pos; var end = "This is not fixed, for each record it should take its latitude/longitude value"; var request = { origin: start, destination: end, travelMode: google.maps.DirectionsTravelMode.DRIVING }; directionsService.route(request, function (response, status) { if (status == google.maps.DirectionsStatus.OK) { directionsDisplay.setDirections(response); computeTotalDistance(response); } }); } function computeTotalDistance(result) { var total = 0; var myroute = result.routes[0]; for (i = 0; i < myroute.legs.length; i++) { total += myroute.legs[i].distance.value; } total = total / 1000; // here i have to show result on label inside repeater, but it giving error: "The name 'lbl_distance' does not exist in the current context" but i have label with this id inside the repeater. document.getElementById('<%= lbl_distance.ClientID %>').innerHTML = total + " km"; } google.maps.event.addDomListener(window, 'load', initialize); </script>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)