There are some workarounds for the cross site AJAX problems. Take this one for instance. It uses a PHP proxy to call a specific site. Create a PHP file with the following content somewhere in a folder that your web server can deliver, call it something like yournavigation.php:

<?php
// PHP Proxy example
// Responds to both HTTP GET and POST requests
//
// Author: Jason Levitt
// December 7th, 2005
//

// Allowed hostname
define ('HOSTNAME', 'http://www.yournavigation.org/');

// Get the REST call path from the AJAX application
// Is it a POST or a GET?
$path = ($_POST['q']) ? $_POST['q'] : $_GET['q'];
$url = "">
// Open the Curl session
$session = curl_init($url);

// If it's a POST, put the POST data in the body
if ($_POST['q']) {
    $postvars = '';
    while ($element = current($_POST)) {
        $postvars .= key($_POST).'='.$element.'&';
        next($_POST);
    }
    curl_setopt ($session, CURLOPT_POST, true);
    curl_setopt ($session, CURLOPT_POSTFIELDS, $postvars);
}

// Don't return HTTP headers. Do return the contents of the call
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

// Make the call
$xml = curl_exec($session);

// The web service returns XML. Set the Content-Type appropriately
header("Content-Type: text/xml");

echo $xml;
curl_close($session);

?>

Then include the following call in your _javascript_ file.

  //Compose request url
  var path = 'gosmore.php?flat=52.215676&flon=5.963946&tlat=52.2573&tlon=6.1799&v=motorcar&fast=1&layer=mapnik';
  // The full path to the PHP proxy
  var kmlFeedUrl = 'yournavigation.php?q=' + encodeURIComponent(path);

Now the URL is local from the _javascript_ point of view.

Regards
Juangui


[email protected] escribió:
Send Routing mailing list submissions to
	[email protected]

To subscribe or unsubscribe via the World Wide Web, visit
	http://lists.openstreetmap.org/listinfo/routing
or, via email, send a message with subject or body 'help' to
	[email protected]

You can reach the person managing the list at
	[email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Routing digest..."


Today's Topics:

   1. Re: OpenLayers, KML: how to display route? (Lambertus)
   2. Re: OpenLayers, KML: how to display route? (Marcus Wolschon)


----------------------------------------------------------------------

Message: 1
Date: Sun, 22 Feb 2009 12:09:32 +0100
From: Lambertus <[email protected]>
Subject: Re: [Routing] OpenLayers, KML: how to display route?
To: [email protected], [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed

A webbrowser does not allow you to do cross site AJAX calls. You will 
need to setup a local proxy on your webserver who relais the 
yournavigation.org queries.


Jav Doorn wrote:
  
Hello,

I am working on a Openstreetmap project which includes routing. I can draw a
map:

map = new OpenLayers.Map( $('map'), {controls: [] } );
layerTilesAtHome = new OpenLayers.Layer.OSM.Osmarender("Osmarender"); 
map.addLayer(layerTilesAtHome); 

The map is drawn correctly.

Next I need to draw a route that is contained in a KML file:

var kmlFeedUrl =
"http://www.yournavigation.org/gosmore.php?flat=52.215676&flon=5.963946&tlat=52.2573&tlon=6.1799&v=motorcar&fast=1&layer=mapnik"

kmlLayer = new OpenLayers.Layer.GML("KML", kmlFeedUrl, {
      projection: new OpenLayers.Projection("EPSG:4326"),
                      format: OpenLayers.Format.KML,
                      formatOptions: {
                        extractStyles: true,
                        extractAttributes: true
                        }
      });

map.addLayer(kmlLayer);

I can step through this code in the debugger without errors in these
particular lines.
As you can see, the url returns a KML file.
Later I get the error ?access denied?. The map is drawn anyway but no route
is displayed.

Can anybody help?


      


------------------------------------------------------------------------

_______________________________________________
Routing mailing list
[email protected]
http://lists.openstreetmap.org/listinfo/routing
    




------------------------------

Message: 2
Date: Sun, 22 Feb 2009 12:22:18 +0100
From: Marcus Wolschon <[email protected]>
Subject: Re: [Routing] OpenLayers, KML: how to display route?
To: [email protected]
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

Lambertus schrieb:
  
A webbrowser does not allow you to do cross site AJAX calls. You will 
need to setup a local proxy on your webserver who relais the 
yournavigation.org queries.
    

I found a way around this limitation a while ago.
It works file to dynamically include a _javascript_ from
that remote site and have it set variables as a replacement
for the ajax-calls.

Marcus



------------------------------

_______________________________________________
Routing mailing list
[email protected]
http://lists.openstreetmap.org/listinfo/routing


End of Routing Digest, Vol 18, Issue 5
**************************************

  

_______________________________________________
Routing mailing list
[email protected]
http://lists.openstreetmap.org/listinfo/routing

Reply via email to