[Routing] Routing Digest, Vol 18, Issue 6

Juan Guillermo Jordán Aldasoro jjordan at robotica.uv.es
Mon Feb 23 14:56:08 GMT 2009


It looks like my last email wasn't properly formatted. I will post it 
again below.

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, and put it in the same web server 
than the JavaScript file showing the KML layer. 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 = HOSTNAME.$path;

// 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


routing-request at openstreetmap.org escribió:
> Send Routing mailing list submissions to
> 	routing at openstreetmap.org
>
> 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
> 	routing-request at openstreetmap.org
>
> You can reach the person managing the list at
> 	routing-owner at openstreetmap.org
>
> 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)
>    3. Re: Routing Digest, Vol 18, Issue 5
>       (Juan Guillermo Jord?n Aldasoro)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Sun, 22 Feb 2009 13:53:10 +0100
> From: Lambertus <osm at na1400.info>
> Subject: Re: [Routing] OpenLayers, KML: how to display route?
> To: routing at openstreetmap.org
> Cc: jvdoorn2003 at yahoo.de
> Message-ID: <49A14AB6.6060607 at na1400.info>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Marcus Wolschon wrote:
>   
>> 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.
>>
>>     
> Ok, I could provide such a javascript file if that makes it easier for 
> other sites to use the YOURS API, but I don't clearly see what should be 
> in there: a variable containing the base URL? And would that be enough, 
> because I cannot pre-set every possible lat/lon in advance?
>
>
>
> ------------------------------
>
> Message: 2
> Date: Mon, 23 Feb 2009 07:47:22 +0100
> From: Marcus Wolschon <Marcus at Wolschon.biz>
> Subject: Re: [Routing] OpenLayers, KML: how to display route?
> To: routing at openstreetmap.org
> Cc: jvdoorn2003 at yahoo.de
> Message-ID: <346bc83d04057c89f725ba8851a7aa64 at kleinbetrieb.biz>
> Content-Type: text/plain; charset=utf-8
>
> On Sun, 22 Feb 2009 13:53:10 +0100, Lambertus <osm at na1400.info> wrote:
>   
>> Marcus Wolschon wrote:
>>     
>>> 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.
>>>
>>>       
>> Ok, I could provide such a javascript file if that makes it easier for 
>> other sites to use the YOURS API, but I don't clearly see what should be 
>> in there: a variable containing the base URL? And would that be enough, 
>> because I cannot pre-set every possible lat/lon in advance?
>>     
>
> No, that I used was a php-script that took URL-parameters and
> gave an output like:
>
> <script language="javascript">
>   answer = "xyz";
>   handleAnswer(answer);
> </script>
>
> Where handleAnswer(param) is a method defined on the website
> (similar to the ajax-handler).
>
> It worked well across domain-boundaries in FF2, FF3,
> Safari, IE5, IE6, IE7 and Chrome.
>
> Marcus
>
>
>
> ------------------------------
>
> Message: 3
> Date: Mon, 23 Feb 2009 11:45:58 +0100
> From: Juan Guillermo Jord?n Aldasoro 	<jjordan at robotica.uv.es>
> Subject: Re: [Routing] Routing Digest, Vol 18, Issue 5
> To: routing at openstreetmap.org
> Message-ID: <49A27E66.2060806 at robotica.uv.es>
> Content-Type: text/plain; charset="us-ascii"
>
> An HTML attachment was scrubbed...
> URL: http://lists.openstreetmap.org/pipermail/routing/attachments/20090223/20e8d207/attachment-0001.htm 
>
> ------------------------------
>
> _______________________________________________
> Routing mailing list
> Routing at openstreetmap.org
> http://lists.openstreetmap.org/listinfo/routing
>
>
> End of Routing Digest, Vol 18, Issue 6
> **************************************
>
>   





More information about the Routing mailing list