I would like to build a block which automatically displays directions from the user location (given by the browser HTML5 geocoding feature for anonymous users or by the stored user location for autenticated users) to the current node location.

Such a module should have three sections in this order:

  1. traffic and bicycling toggle buttons
  2. map with graphical directions
  3. textual directions
  4. travel mode & travel options
  5. "recompute directions" button

Would it be possible using Get Directions?

Comments

hutch’s picture

Probably.
From location enabled authenticated users to a location enabled node can be done with function getdirections_u2n_setlocation()

If you have lat/lon use can use
function getdirections_locations()

If you configure Getdirections to use v3 Googlemaps API and use advanced settings and alternate method for displaying the route the map will automatically recalculate if the route is dragged.

Read the README, look at comments in getdirections.api.inc and in getdirections.module and you should be able to get where you want.

I don't know how you would obtain the browser HTML5 geocoding feature information but I imagine that this could be done using javascript to grab it and ajax to send it to a function on the server.

cesareaugusto’s picture

First, thank you really much for your quick support!

This is the code I put in my custom block.

global $user;

if ($user->uid) {
if (arg(0) == 'node') {
$nid = arg(1);
if (is_numeric($nid) && $nid > 0) {
echo getdirections_u2n_setlocation($uid, $nid);
}
}
}

else {
if (arg(0) == 'node') {
$nid = arg(1);
if (is_numeric($nid) && $nid > 0) {
echo getdirections_u2n_setlocation(getCurrentPosition(), $nid);
}
}
}

Of course it doesn't work. The W3C method for getting user location by the browser should be getCurrentPosition().

What should I change?

hutch’s picture

getCurrentPosition() is a javascript function, see http://dev.w3.org/geo/api/spec-source.html for the specifications.
You can't insert a javascript function straight into a php function ;-)

Remember that browser location only makes sense on mobile devices, my main workstation returns a location that is several hundred miles away....

You might find more howto by googling.

http://jquery-howto.blogspot.com/2009/04/get-geographical-location-geolo...
http://code.google.com/p/geo-location-javascript/

ocamp’s picture

ok,

I found this code.

HTML

<div id="location">
<body onload="getLocation()">
</div>

JS

<script>
var x=document.getElementById("location");
function getLocation()
  {
  if (navigator.geolocation)
    {
    navigator.geolocation.getCurrentPosition(showPosition);
    }
  else{x.innerHTML="Geolocation is not supported by this browser.";}
  }
function showPosition(position)
  {
  x.innerHTML="Latitude: " + position.coords.latitude + 
  "<br />Longitude: " + position.coords.longitude;	
  }
</script>

this simply shows the lat/lon in a location div on a page.

would you be able to implement a current location to node function.

Or how can I use getdirections/to/node/1 and auto fil the from field using the lat/lon retrieved from the script?

hutch’s picture

Try "getdirections/latlon/from/lat,lon/somewhere"
Where lat,lon is a latitude,longitude pair and "somewhere" is a description of 'from'

ocamp’s picture

ok so I can use /getdirections/latlon/from/(lat,lon)/me

to get the current users postion called me.

How can I put a to destination on now. like

/getdirections/latlon/from/(lat,lon)/me/to/1

where 1 is node/1

hutch’s picture

You could put "the current location" instead of "somewhere". You do not have a node/[nid], you only have whatever navigator.geolocation returned and that could be anywhere.