Hi all im hoping you can help, I have been wracking my brains out for
ages with this and any pointers would be much appreciated.
I have the following code :
<script type="text/javascript">
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer();
var myOptions = {
zoom:7,
trips:1,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map"),
myOptions);
directionsDisplay.setMap(map);
var request = {
origin: '51.030923,-3.12192',
destination: '51.111983,-2.991114',
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
// Display the distance:
document.getElementById('distance').innerHTML +=
response.routes[0].legs[0].distance.text + " meters";
// Display the duration:
document.getElementById('duration').innerHTML +=
response.routes[0].legs[0].duration.text + " seconds";
// Display the duration:
for (var i = 0; i < response.routes[0].legs[0].steps.length;
i++)
document.getElementById('direction').innerHTML +=
response.routes[0].legs[0].steps[i].instructions + "<br>";
};
directionsDisplay.setDirections(response);
});
</script>
As you see very basic finding directions from two places and getting
directions. But what I cant find how to do, and honestly I have been
looking at this all week is how to turn ''origin:
'51.030923,-3.12192'," from being hard coded to a geolocation lat and
long....
I have tried using :
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
initialLocation = new
google.maps.LatLng(position.coords.latitude,position.coords.longitude);
origin: initialLocation,
destination: '51.111983,-2.991114',
travelMode: google.maps.DirectionsTravelMode.DRIVING
}, function() {
handleNoGeolocation(browserSupportFlag);
});
} else {
// Browser doesn't support Geolocation
handleNoGeolocation();
}
but to no avail...
I have looked at implementing
navigator.geolocation.getCurrentPosition(function(position){
var lat = position.coords.latitude;
var lon = position.coords.longitude;
var origin = new GMarker(new GLatLng(lat, lon));
var jsMap = new GMap2(document.getElementById("jsMap"));
jsMap.addOverlay(marker);
},function(error){
//use error.code to determine what went wrong
});
I just cant see how to do it....
Any help in this would be very much appreciated.
regards
Ade
--
You received this message because you are subscribed to the Google Groups
"Google Maps JavaScript API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-js-api-v3?hl=en.