Hello,

I try to use part of the example http://openlayers.org/dev/examples/openls.html to include a map in my website and let users search for the address. But I alway get a null-value as response.responseXML.

To verify that I have no error in my code I have copied the whole example to my site. Calling it shows the same error as the code in my own site (for the example see code below).

I found a posting in an OSM-forum that I have to use a proxy and so I have installed proxy.php from the mapbuilder-site and changed the code like follows:

            function init() {
            OpenLayers.ProxyHost = "proxy.php?url=";
            map = new OpenLayers.Map('map', {
                controls: [
                    new OpenLayers.Control.PanZoom(),
                    new OpenLayers.Control.Navigation()
                ]
            });
            layer = new OpenLayers.Layer.OSM("OpenStreetMap", null, {
                transitionEffect: 'resize'
            });
            map.addLayers([layer]);
            map.zoomToMaxExtent();
        }
        function submitform() {
           var queryString = document.forms[0].query.value;
            OpenLayers.Request.POST({
                url: "http://www.openrouteservice.org/php/OpenLSLUS_Geocode.php",
                scope: this,
                failure: this.requestFailure,
                success: this.requestSuccess,
                headers: {"Content-Type": "application/x-www-form-urlencoded"},
                data: "FreeFormAdress=" + encodeURIComponent(queryString) + "&MaxResponse=1"
            });
        }
        function requestSuccess(response) {
alert(response.responseXML);
            var format = new OpenLayers.Format.XLS();
            var output = format.read(response.responseXML);
            if (output.responseLists[0]) {
                var geometry = output.responseLists[0].features[0].geometry;
                var foundPosition = new OpenLayers.LonLat(geometry.x, geometry.y).transform(
                        new OpenLayers.Projection("EPSG:4326"),
                        map.getProjectionObject()
                        );
                map.setCenter(foundPosition, 16);
            } else {
                alert("Sorry, no address found");
            }
        }
        function requestFailure(response) {
            alert("An error occurred while communicating with the OpenLS service. Please try again.");
        }

The alert in function requestSuccess(response) returns null whatever I set as proxy. I have tried with "", "proxy.php", "proxy.php?url=", all with the same result. The only diffenrence ist that with "" there are about 5 seconds from calling the service until I get the result. In all other cases (using the proxy.php) the result comes in less than one second.

What is wrong in my code?

(I also tried to use proxy.cgi, but this won't work on my server - I get an 500 internal-server-error)

Thank you for all tipps!

asked 29 Dec '11, 21:04

s_glodek's gravatar image

s_glodek
16113
accept rate: 0%

edited 31 Jan '13, 17:54

SimonPoole's gravatar image

SimonPoole ♦
38.1k13284605


Are you sure that your proxy script is working? You can test this by pointing your normal browser to http://localhost/proxy.php?url=http://a.tile.openstreetmap.org/0/0/0.png Your proxy script needs to support POST as well as GET.

You may want to open the debuging tools in your browser and see what requests get sent and what error messeges you get from them.

permanent link

answered 30 Dec '11, 01:11

Gnonthgol's gravatar image

Gnonthgol ♦
13.6k15101198
accept rate: 16%

Jippiyeah!! I have it!!

The error ist the Content-Type: application/xml in the POST-request. I changed it to "Content-Type: application/x-www-form-urlencodedrn" and now it works!

Thanks to Gnonthgol for the hint to use the debug-tools of the browser and to google to find a posting with a short description to send a post in php :-).

(31 Dec '11, 12:32) s_glodek

Please use the OpenLayers proxy.cgi explained here: http://trac.osgeo.org/openlayers/wiki/FrequentlyAskedQuestions#ProxyHost

The normal OpenLayers proxy.cgi already contains the OpenRouteService host. See here: http://trac.osgeo.org/openlayers/browser/trunk/openlayers/examples/proxy.cgi

Please beware that the proxy script has the right permission to execute! Hope that helps :)

permanent link

answered 30 Dec '11, 08:34

pascal's gravatar image

pascal
713
accept rate: 0%

I'm not able to use proxy.cgi - it always returns 500 - server error.

Using proxy.php I can see with firebug that proxy.php sends the following request:

POST /php/OpenLSLUS_Geocode.php? HTTP/1.0
Host:www.openrouteservice.org
User-Agent: MyAgent
Content-Type: application/xml
Content-Length: 62

FreeFormAdress=Rue%20des%20Berges%2037%20Payerne&MaxResponse=1

The answer from www.openrouteservice.org is

HTTP/1.1 200 OK
Date: Sat, 31 Dec 2011 11:57:44 GMT
Server: Apache
X-Powered-By: PHP/5.2.6-1+lenny13
Vary: Accept-Encoding
Content-Length: 20
Connection: close
Content-Type: text/html

Nix uebermittelt!!

It seems to be an error in transferring the POST-data. The proxy.php-script is available as text-file on http://osm.glodek-edv.de/proxy.txt and the test-site is http://osm.glodek-edv.de/openls.html

(31 Dec '11, 12:09) s_glodek
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×164
×1

question asked: 29 Dec '11, 21:04

question was seen: 6,289 times

last updated: 31 Jan '13, 17:54

powered by OSQA