About query
WHERE geom_way && expand(st_geomfromtext('Point('|| 10.426925 || ' ' || 36.611049 ||')',4326), 0.01)
It could be faster with :
WHERE ST_DWithin(geom_way , st_geomfromtext('Point('|| 10.426925 || ' ' || 36.611049 ||')',4326), 0.01) -- (did not test)
If you want closest point on line see ST_ClosestPoint(geom,geom) So query should be something like this assuming that your green line is one geom (which it probably is not).
SELECT osm_name, ST_ClosestPoint(linegeom, pointgeom) as point_on_line, ST_Distance(st_geomfromtext('Point('|| 10.426925 || ' ' || 36.611049 ||')',4326),geom_way) AS dist
FROM af_2po_4pgr WHERE ST_DWithin(geom_way , st_geomfromtext('Point('|| 10.426925 || ' ' || 36.611049 ||')',4326), 0.01) ORDER BY ST_Distance(st_geomfromtext('Point('|| 10.426925 || ' ' || 36.611049 ||')',4326),geom_way) ASC LIMIT 1 --(not tested)
Now if that green line is actually a route which is returned with pg_dijkstra or similar pgrouting algorithm you can use than return set as table for closest point query. If it in osmpo you probably can get all those ids out from it, maybe,i don't know. And use those ids like this. As long as there is indexes it should be way faster than 3s.
SELECT ..... FROM (select * FROM af_2po_4pgr WHERE some_id IN ( 123,31232,321,...) as data
You can replace that IN ( ) with IN ( SELECT edge_id from shortest_path(...)) ( <- is not correct pgrouting shortest_path function, pgr_results and pgr_costresults3 returns edgeids, so it can be used to limit closest point search and if you do routing with pgrouting you can get all results in one query )
-- CREATE INDEX idx_hh_2po_4pgr_geom_way ON hh_2po_4pgr USING GIST (geom_way GIST_GEOMETRY_OPS);And it's a good idea to use a bounding-box around your points. Nevertheless this question rather belongs to the postGIS area. – Carsten Mar 10 '14 at 18:41